Trait Num

Source
pub trait Num:
    Sized
    + Copy
    + AddAssign
    + SubAssign
    + Ord
    + Sub<Output = Self>
    + Neg<Output = Self>
    + Eq
    + Add<Output = Self> {
    const ZERO: Self;
    const ONE: Self;
    const TWO: Self;

    // Required methods
    fn iter_range(range: Range<Self>) -> impl Iterator<Item = Self>;
    fn as_u64(self) -> u64;
}
Expand description

A helper trait for specifying generic numeric types.

Required Associated Constants§

Source

const ZERO: Self

The neutral value for addition and subtraction.

Source

const ONE: Self

The neutral value for multiplication and division.

Source

const TWO: Self

For when you can’t use + in const contexts, but need a 2

Required Methods§

Source

fn iter_range(range: Range<Self>) -> impl Iterator<Item = Self>

Iterate over a range. Workaround to std::ops::Range’s Iterator impl not being implementable for custom types.

Source

fn as_u64(self) -> u64

Convert the value to a u64. Used for seeding random number generators from coordinates.

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.

Implementations on Foreign Types§

Source§

impl Num for i64

Source§

const ZERO: i64 = 0i64

Source§

const ONE: i64 = 1i64

Source§

const TWO: i64 = 2i64

Source§

fn iter_range(range: Range<Self>) -> impl Iterator<Item = Self>

Source§

fn as_u64(self) -> u64

Implementors§

Source§

impl<C> Num for GridIndex<C>

Source§

const ZERO: Self

Source§

const ONE: Self

Source§

const TWO: Self