num::traits

Trait One

Source
pub trait One: Sized + Mul<Output = Self> {
    // Required method
    fn one() -> Self;

    // Provided methods
    fn set_one(&mut self) { ... }
    fn is_one(&self) -> bool
       where Self: PartialEq { ... }
}
Expand description

Defines a multiplicative identity element for Self.

§Laws

a * 1 = a       ∀ a ∈ Self
1 * a = a       ∀ a ∈ Self

Required Methods§

Source

fn one() -> Self

Returns the multiplicative identity element of Self, 1.

§Purity

This function should return the same result at all times regardless of external mutable state, for example values stored in TLS or in static muts.

Provided Methods§

Source

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.

Source

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity.

For performance reasons, it’s best to implement this manually. After a semver bump, this method will be required, and the where Self: PartialEq bound will be removed.

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 One for f32

Source§

fn one() -> f32

Source§

fn is_one(&self) -> bool

Source§

impl One for f64

Source§

fn one() -> f64

Source§

fn is_one(&self) -> bool

Source§

impl One for i8

Source§

fn one() -> i8

Source§

fn is_one(&self) -> bool

Source§

impl One for i16

Source§

fn one() -> i16

Source§

fn is_one(&self) -> bool

Source§

impl One for i32

Source§

fn one() -> i32

Source§

fn is_one(&self) -> bool

Source§

impl One for i64

Source§

fn one() -> i64

Source§

fn is_one(&self) -> bool

Source§

impl One for i128

Source§

fn one() -> i128

Source§

fn is_one(&self) -> bool

Source§

impl One for isize

Source§

fn one() -> isize

Source§

fn is_one(&self) -> bool

Source§

impl One for u8

Source§

fn one() -> u8

Source§

fn is_one(&self) -> bool

Source§

impl One for u16

Source§

fn one() -> u16

Source§

fn is_one(&self) -> bool

Source§

impl One for u32

Source§

fn one() -> u32

Source§

fn is_one(&self) -> bool

Source§

impl One for u64

Source§

fn one() -> u64

Source§

fn is_one(&self) -> bool

Source§

impl One for u128

Source§

fn one() -> u128

Source§

fn is_one(&self) -> bool

Source§

impl One for usize

Source§

fn one() -> usize

Source§

fn is_one(&self) -> bool

Source§

impl<T> One for Wrapping<T>
where T: One, Wrapping<T>: Mul<Output = Wrapping<T>>,

Source§

fn set_one(&mut self)

Source§

fn one() -> Wrapping<T>

Implementors§

Source§

impl One for BigInt

Source§

impl One for BigUint

Source§

impl<T> One for Ratio<T>
where T: Clone + Integer,

Source§

impl<T> One for Complex<T>
where T: Clone + Num,