Struct bellframe::Bell[][src]

pub struct Bell { /* fields omitted */ }
Expand description

A type-safe representation of a ‘bell’, which adds things like conversions to and from commonly-used bell names.

Implementations

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 proj_core::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);

Creates a Bell from a 0-indexed integer.

Example

use proj_core::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");

Creates a Bell from a 1-indexed integer. This could fail if number is 0, so in that case None is returned.

Example

use proj_core::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);

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 proj_core::{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)?);

A Bell representing the ‘treble’ on any stage. Equivalent to Bell::from_name('1').unwrap().

Example

use proj_core::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");

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 proj_core::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);

Returns the 0-indexed representation of this Bell.

Example

use proj_core::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);

Returns the 1-indexed representation of this Bell.

Example

use proj_core::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);

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 proj_core::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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.