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§
Provided Methods§
Sourcefn is_one(&self) -> boolwhere
Self: PartialEq,
fn is_one(&self) -> boolwhere
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
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 }
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.