One

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 98)
90    fn mod_inv(self, modulo: Self) -> Self {
91        assert!(
92            !self.is_zero(),
93            "attempt to inverse zero with modulo {}",
94            modulo
95        );
96        let extgcd = self.signed().extgcd(modulo.signed());
97        assert!(
98            extgcd.g.is_one(),
99            "there is no inverse {} modulo {}",
100            self,
101            modulo
102        );
103        extgcd.x.rem_euclid(modulo.signed()).unsigned()
104    }
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    }
crates/competitive/src/math/mint_matrix.rs (line 60)
41    fn determinant_linear_non_singular(mut self, mut other: Self) -> Option<Vec<MInt<M>>>
42    where
43        M: MIntBase,
44    {
45        let n = self.data.len();
46        let mut f = MInt::one();
47        for d in 0..n {
48            let i = other.data.iter().position(|other| !other[d].is_zero())?;
49            if i != d {
50                self.data.swap(i, d);
51                other.data.swap(i, d);
52                f = -f;
53            }
54            f *= other[d][d];
55            let r = other[d][d].inv();
56            for j in 0..n {
57                self[d][j] *= r;
58                other[d][j] *= r;
59            }
60            assert!(other[d][d].is_one());
61            for i in d + 1..n {
62                let a = other[i][d];
63                for k in 0..n {
64                    self[i][k] = self[i][k] - a * self[d][k];
65                    other[i][k] = other[i][k] - a * other[d][k];
66                }
67            }
68            for j in d + 1..n {
69                let a = other[d][j];
70                for k in 0..n {
71                    self[k][j] = self[k][j] - a * self[k][d];
72                    other[k][j] = other[k][j] - a * other[k][d];
73                }
74            }
75        }
76        for s in self.data.iter_mut() {
77            for s in s.iter_mut() {
78                *s = -*s;
79            }
80        }
81        let mut p = self.characteristic_polynomial();
82        for p in p.iter_mut() {
83            *p *= f;
84        }
85        Some(p)
86    }
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>