#[repr(transparent)]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
sourceimpl 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
sourceimpl AddAssign<u8> for Bell
impl AddAssign<u8> for Bell
sourcefn add_assign(&mut self, rhs: u8)
fn add_assign(&mut self, rhs: u8)
Performs the += operation. Read more
sourceimpl Ord for Bell
impl Ord for Bell
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<Bell> for Bell
impl PartialOrd<Bell> for Bell
sourcefn partial_cmp(&self, other: &Bell) -> Option<Ordering>
fn partial_cmp(&self, other: &Bell) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl SubAssign<u8> for Bell
impl SubAssign<u8> for Bell
sourcefn sub_assign(&mut self, rhs: u8)
fn sub_assign(&mut self, rhs: u8)
Performs the -= operation. Read more
impl 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key and return true if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more