pub struct Bell { /* private fields */ }Expand description
A type-safe representation of a ‘bell’, which adds things like conversions to and from
commonly-used bell names. Each Bell takes a single byte in memory.
Implementations§
source§impl Bell
impl Bell
sourcepub fn from_name(c: char) -> Option<Bell>
pub fn from_name(c: char) -> Option<Bell>
Creates a Bell from a char containing a bell name (e.g. '4' or 'T'). If the name
is not valid, then this fails and returns None. Note that lower case chars are not
considered valid bell names.
Example
use bellframe::Bell;
// Converting a valid name to a `Bell` and back should be the identity function
assert_eq!(Bell::from_name('1')?.name(), "1");
assert_eq!(Bell::from_name('5')?.name(), "5");
assert_eq!(Bell::from_name('0')?.name(), "0");
assert_eq!(Bell::from_name('T')?.name(), "T");
// Converting a lower-case letter should return `None`, even if the upper case
// version is valid
assert_eq!(Bell::from_name('e'), None);
assert_eq!(Bell::from_name('t'), None);
// Converting any old rubbish will return `None` (no shade on Ferris)
assert_eq!(Bell::from_name('\r'), None);
assert_eq!(Bell::from_name('🦀'), None);sourcepub fn from_index(index: u8) -> Bell
pub fn from_index(index: u8) -> Bell
Creates a Bell from a 0-indexed integer.
Panics
Panics if 255 is passed (a Bell with index 255 would imply a Stage of 256, which
cannot be created).
Example
use bellframe::Bell;
// A 'Bell' with index 0 is the treble
assert_eq!(Bell::from_index(0).name(), "1");
// A 'Bell' with index 11 is the '12' or 'T'
assert_eq!(Bell::from_index(11).name(), "T");sourcepub fn from_number(number: u8) -> Option<Bell>
pub fn from_number(number: u8) -> Option<Bell>
Creates a Bell from a 1-indexed integer. This could fail if number is 0, so in that
case None is returned.
Example
use bellframe::Bell;
// The `Bell` with number '12' is the 12th and should be displayed as 'T'
assert_eq!(Bell::from_number(12)?.name(), "T");
// Trying to create a Bell with number `0` fails:
assert_eq!(Bell::from_number(0), None);sourcepub fn tenor(stage: Stage) -> Bell
pub fn tenor(stage: Stage) -> Bell
Creates the Bell representing the tenor or heaviest bell on a given Stage. This
could fail if the Stage has no Bells, so in that case None is returned.
Example
use bellframe::{Bell, Stage};
// The **5** is the 'tenor' when ringing Doubles
assert_eq!(Bell::tenor(Stage::DOUBLES), Bell::from_number(5)?);
// The 12 is the tenor on maximus
assert_eq!(Bell::tenor(Stage::MAXIMUS), Bell::from_number(12)?);sourcepub const TREBLE: Bell = _
pub const TREBLE: Bell = _
A Bell representing the ‘treble’ on any stage. Equivalent to
Bell::from_name('1').unwrap().
Example
use bellframe::Bell;
// `TREBLE` should be the bell with name '1'
assert_eq!(Bell::from_name('1'), Some(Bell::TREBLE));
// The `TREBLE` has index 0, and its number is 1
assert_eq!(Bell::TREBLE.index(), 0);
assert_eq!(Bell::TREBLE.number(), 1);
// The treble should display as `"1"`
assert_eq!(Bell::TREBLE.name(), "1");sourcepub fn to_char(self) -> Option<char>
pub fn to_char(self) -> Option<char>
Converts this Bell into the char that it should be displayed as. If the Bell is
too big to have a corresponding name, then None is returned.
Example
use bellframe::Bell;
// A 'Bell' with index 0 is the treble, and therefore displays as `1`
assert_eq!(Bell::from_index(0).to_char(), Some('1'));
// The 11th should display as 'E'
assert_eq!(Bell::from_number(11)?.to_char(), Some('E'));
// Trying to display the 100th Bell fails:
assert_eq!(Bell::from_number(100)?.to_char(), None);sourcepub fn index(self) -> usize
pub fn index(self) -> usize
Returns the 0-indexed representation of this Bell.
Example
use bellframe::Bell;
// Creating a `Bell` with `from_index` should return the same index passed to it
assert_eq!(Bell::from_index(0).index(), 0);
assert_eq!(Bell::from_index(12).index(), 12);
assert_eq!(Bell::from_name('8')?.index(), 7);
assert_eq!(Bell::from_name('0')?.index(), 9);
assert_eq!(Bell::from_name('T')?.index(), 11);sourcepub fn index_u8(self) -> u8
pub fn index_u8(self) -> u8
Returns the 0-indexed representation of this Bell, as a u8.
Example
use bellframe::Bell;
// Creating a `Bell` with `from_index` should return the same index passed to it
assert_eq!(Bell::from_index(0).index_u8(), 0);
assert_eq!(Bell::from_index(12).index_u8(), 12);
assert_eq!(Bell::from_name('8')?.index_u8(), 7);
assert_eq!(Bell::from_name('0')?.index_u8(), 9);
assert_eq!(Bell::from_name('T')?.index_u8(), 11);sourcepub fn number(self) -> u8
pub fn number(self) -> u8
Returns the 1-indexed representation of this Bell.
Example
use bellframe::Bell;
assert_eq!(Bell::from_index(0).number(), 1);
assert_eq!(Bell::from_name('0')?.number(), 10);
// Using `from_number` should return the same number that was passed to it
assert_eq!(Bell::from_number(4)?.number(), 4);
assert_eq!(Bell::from_number(10)?.number(), 10);sourcepub fn name(self) -> String
pub fn name(self) -> String
Converts this Bell into a String that it should be displayed as. Unlike
to_char, this does not fail if the Bell is to big to have a name.
Instead, it returns the 1-indexed ‘number’ of the Bell in angle brackets.
Example
use bellframe::Bell;
// Bells which are <= 9th should return their number as a `String`
assert_eq!(Bell::from_number(1)?.name(), "1");
assert_eq!(Bell::from_number(5)?.name(), "5");
assert_eq!(Bell::from_number(9)?.name(), "9");
// The 10th display as "0"
assert_eq!(Bell::from_number(10)?.name(), "0");
// Other bells display as their single-character names
assert_eq!(Bell::from_number(12)?.name(), "T");
assert_eq!(Bell::from_number(16)?.name(), "D");
// Anything too big simply displays as '<{bell.number()}>'
assert_eq!(Bell::from_number(100)?.name(), "<100>");Trait Implementations§
source§impl AddAssign<i16> for Bell
impl AddAssign<i16> for Bell
source§fn add_assign(&mut self, rhs: i16)
fn add_assign(&mut self, rhs: i16)
+= operation. Read moresource§impl Ord for Bell
impl Ord for Bell
source§impl PartialEq<Bell> for Bell
impl PartialEq<Bell> for Bell
source§impl PartialOrd<Bell> for Bell
impl PartialOrd<Bell> for Bell
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl SubAssign<i16> for Bell
impl SubAssign<i16> for Bell
source§fn sub_assign(&mut self, rhs: i16)
fn sub_assign(&mut self, rhs: i16)
-= operation. Read moreimpl Copy for Bell
impl Eq for Bell
impl StructuralEq for Bell
impl StructuralPartialEq for Bell
Auto Trait Implementations§
impl RefUnwindSafe for Bell
impl Send for Bell
impl Sync for Bell
impl Unpin for Bell
impl UnwindSafe for Bell
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.