Stage

Struct Stage 

Source
pub struct Stage(/* private fields */);
Expand description

A newtype over u8 that represents a stage. All Stages must contain at least one Bell; zero-bell Stages cannot be created without using incorrect unsafe code.

To create a new Stage, you can either create it directly with Stage::try_from (which returns a Result) or with Stage::new (which panics if passed 0).

If you want a specific small Stage, then you can use the constants for the human name for each Stage:

use bellframe::Stage;

// Converting from numbers is the same as using the constants
assert_eq!(Stage::SINGLES, Stage::new(3));
assert_eq!(Stage::MAJOR, Stage::new(8));
assert_eq!(Stage::CINQUES, Stage::new(11));
assert_eq!(Stage::SIXTEEN, Stage::new(16));
// We can use `Stage::from` to generate `Stage`s that don't have names
assert_eq!(Stage::new(100).num_bells(), 100);
assert_eq!(Stage::new(254).num_bells(), 254);

Stages with human-friendly names are Displayed as their names:

assert_eq!(Stage::MAXIMUS.to_string(), "Maximus");
assert_eq!(Stage::new(9).to_string(), "Caters");
assert_eq!(Stage::new(50).to_string(), "50 bells");

Implementations§

Source§

impl Stage

Source

pub fn new(num_bells: u8) -> Stage

Creates a new Stage representing a given number of Bells.

§Panics

Panics if num_bells is zero.

Source

pub fn num_bells(self) -> usize

The number of Bells in this Stage. This is guaranteed to be non-zero.

§Example
use bellframe::Stage;

assert_eq!(Stage::DOUBLES.num_bells(), 5);
assert_eq!(Stage::MAXIMUS.num_bells(), 12);
Source

pub fn num_bells_u8(self) -> u8

The number of Bells in this Stage as a u8. This is guaranteed to be non-zero.

§Example
use bellframe::Stage;

assert_eq!(Stage::DOUBLES.num_bells(), 5);
assert_eq!(Stage::MAXIMUS.num_bells(), 12);
Source

pub fn tenor(self) -> Bell

Returns the highest numbered Bell in this Stage

Source

pub fn bells(self) -> impl DoubleEndedIterator<Item = Bell>

Gets an Iterator over the Bells contained within this Stage, in increasing order.

Source

pub fn contains(self, bell: Bell) -> bool

Returns true if a given Bell is contained in this Stage.

Source

pub fn is_even(self) -> bool

Returns true if this Stage denotes an even number of Bells

Source

pub fn from_lower_case_name(name: &str) -> Option<Stage>

Creates a Stage from the lower case version of the human-friendly name (e.g. "royal", "triples" or "twenty-two").

Source

pub fn name(self) -> Option<&'static str>

Gets the human-friendly name of this Stage, as would be used in Method names (or None if self is too big to have a name).

Source

pub fn checked_add(self, rhs: u8) -> Option<Self>

Source

pub fn checked_sub(self, rhs: u8) -> Option<Self>

Source

pub fn extent(self) -> SameStageVec

Returns a SameStageVec containing one copy of every Row possible in this Stage in some arbitrary order.

Source§

impl Stage

User-friendly constants for commonly used Stages.

§Example

use bellframe::Stage;

assert_eq!(Stage::MINIMUS, Stage::new(4));
assert_eq!(Stage::MINOR, Stage::new(6));
assert_eq!(Stage::TRIPLES, Stage::new(7));
assert_eq!(Stage::FOURTEEN, Stage::new(14));
assert_eq!(Stage::SEPTUPLES, Stage::new(15));
Source

pub const ONE: Stage

A Stage with 1 ‘working’ bell

Source

pub const TWO: Stage

A Stage with 2 working bells

Source

pub const SINGLES: Stage

A Stage with 3 working bells

Source

pub const MINIMUS: Stage

A Stage with 4 working bells

Source

pub const DOUBLES: Stage

A Stage with 5 working bells

Source

pub const MINOR: Stage

A Stage with 6 working bells

Source

pub const TRIPLES: Stage

A Stage with 7 working bells

Source

pub const MAJOR: Stage

A Stage with 8 working bells

Source

pub const CATERS: Stage

A Stage with 9 working bells

Source

pub const ROYAL: Stage

A Stage with 10 working bells

Source

pub const CINQUES: Stage

A Stage with 11 working bells

Source

pub const MAXIMUS: Stage

A Stage with 12 working bells

Source

pub const SEXTUPLES: Stage

A Stage with 13 working bells

Source

pub const FOURTEEN: Stage

A Stage with 14 working bells

Source

pub const SEPTUPLES: Stage

A Stage with 15 working bells

Source

pub const SIXTEEN: Stage

A Stage with 16 working bells

Trait Implementations§

Source§

impl Add<u8> for Stage

Source§

type Output = Stage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u8) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Stage

Source§

fn clone(&self) -> Stage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Stage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Stage

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Stage

Source§

fn cmp(&self, other: &Stage) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Stage

Source§

fn eq(&self, other: &Stage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Stage

Source§

fn partial_cmp(&self, other: &Stage) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub<u8> for Stage

Source§

type Output = Stage

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u8) -> Self::Output

Performs the - operation. Read more
Source§

impl TryFrom<u8> for Stage

Source§

type Error = ZeroStageError

The type returned in the event of a conversion error.
Source§

fn try_from(num_bells: u8) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Stage

Source§

impl Eq for Stage

Source§

impl StructuralPartialEq for Stage

Auto Trait Implementations§

§

impl Freeze for Stage

§

impl RefUnwindSafe for Stage

§

impl Send for Stage

§

impl Sync for Stage

§

impl Unpin for Stage

§

impl UnwindSafe for Stage

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more