Trait One

Source
pub trait One: Sized {
    // Required method
    fn one() -> Self;

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

Required Methods§

Source

fn one() -> Self

Provided Methods§

Source

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

Examples found in repository?
crates/competitive/src/num/integer.rs (line 121)
113    fn modinv(self, modulo: Self) -> Self {
114        assert!(
115            !self.is_zero(),
116            "attempt to inverse zero with modulo {}",
117            modulo
118        );
119        let extgcd = self.extgcd(modulo);
120        assert!(
121            extgcd.g.is_one(),
122            "there is no inverse {} modulo {}",
123            self,
124            modulo
125        );
126        extgcd.x.rem_euclid(modulo.signed()).unsigned()
127    }
More examples
Hide additional examples
crates/competitive/src/algorithm/stern_brocot_tree.rs (line 81)
71    fn from(r: URational<T>) -> Self {
72        assert!(!r.num.is_zero(), "rational must be positive");
73        assert!(!r.den.is_zero(), "rational must be positive");
74
75        let (mut a, mut b) = (r.num, r.den);
76        let mut path = vec![];
77        loop {
78            let x = a / b;
79            a %= b;
80            if a.is_zero() {
81                if !x.is_one() {
82                    path.push(x - T::one());
83                }
84                break;
85            }
86            path.push(x);
87            swap(&mut a, &mut b);
88        }
89        Self { path }
90    }
Source

fn set_one(&mut self)

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() -> Self

Source§

impl One for f64

Source§

fn one() -> Self

Source§

impl One for i8

Source§

fn one() -> Self

Source§

impl One for i16

Source§

fn one() -> Self

Source§

impl One for i32

Source§

fn one() -> Self

Source§

impl One for i64

Source§

fn one() -> Self

Source§

impl One for i128

Source§

fn one() -> Self

Source§

impl One for isize

Source§

fn one() -> Self

Source§

impl One for u8

Source§

fn one() -> Self

Source§

impl One for u16

Source§

fn one() -> Self

Source§

impl One for u32

Source§

fn one() -> Self

Source§

impl One for u64

Source§

fn one() -> Self

Source§

impl One for u128

Source§

fn one() -> Self

Source§

impl One for usize

Source§

fn one() -> Self

Implementors§

Source§

impl One for Decimal

Source§

impl One for DoubleDouble

Source§

impl One for Float32

Source§

impl One for Float64

Source§

impl One for QuadDouble

Source§

impl<M> One for MInt<M>
where M: MIntBase,

Source§

impl<T> One for Complex<T>
where T: Zero + One,

Source§

impl<T> One for DualNumber<T>
where T: Zero + One,

Source§

impl<T> One for Rational<T>
where T: Signed,

Source§

impl<T> One for Saturating<T>
where T: One,

Source§

impl<T> One for URational<T>
where T: Unsigned,

Source§

impl<T> One for Wrapping<T>
where T: One,

Source§

impl<T, C> One for FormalPowerSeries<T, C>
where T: PartialEq + One,

Source§

impl<T: Zero + One> One for Polynomial<T>