Trait Ordinal

Source
pub trait Ordinal:
    Sized
    + Eq
    + PartialEq
    + Ord
    + PartialOrd
    + Hash
    + Clone
    + Copy
    + Default
    + Display
    + Debug {
    type IntegerType: Copy + Display;

    // Required methods
    fn first() -> Self;
    fn next(self) -> Self;
    fn into0(self) -> Self::IntegerType;
    fn into1(self) -> Self::IntegerType;
    fn try_from0(t: Self::IntegerType) -> Option<Self>;
    fn try_from1(t: Self::IntegerType) -> Option<Self>;

    // Provided methods
    fn from0(t: Self::IntegerType) -> Self { ... }
    fn from1(t: Self::IntegerType) -> Self { ... }
}
Expand description

An ordinal number type

See the module-level documentation for more.

Required Associated Types§

Source

type IntegerType: Copy + Display

This type by which this ordinal type is represented

Required Methods§

Source

fn first() -> Self

The first ordinal number

Source

fn next(self) -> Self

Computes the ordinal number that comes after this one

Source

fn into0(self) -> Self::IntegerType

Returns the equivalent integer assuming the ordinal number is 0-based

Source

fn into1(self) -> Self::IntegerType

Returns the equivalent integer assuming the ordinal number is 1-based

Source

fn try_from0(t: Self::IntegerType) -> Option<Self>

Tries to convert an integer to a 0-based ordinal number.

It returns None if the provided number is the highest number of that integer type. This fails because that number can’t be incremented by 1.

Source

fn try_from1(t: Self::IntegerType) -> Option<Self>

Tries to convert an integer to a 1-based ordinal number.

It returns None if the provided number is 0.

Provided Methods§

Source

fn from0(t: Self::IntegerType) -> Self

Converts an integer to a 0-based ordinal number.

§Panics

Panics if the provided number is the highest number of that integer type. This fails because that number can’t be incremented by 1.

Source

fn from1(t: Self::IntegerType) -> Self

Converts an integer to a 1-based ordinal number.

§Panics

Panics if the provided number is 0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§