pub trait NumberUtils {
// Required methods
fn factorial(&self) -> Self;
fn permutation(&self, k: u32) -> Self;
fn combination(&self, k: u32) -> Self;
fn gcd(&self, m: Self) -> Self;
fn lcm(&self, m: Self) -> Self;
fn isqrt(&self) -> Self;
fn checked_factorial(&self) -> Option<Self>
where Self: Sized;
fn checked_permutation(&self, k: u32) -> Option<Self>
where Self: Sized;
fn checked_combination(&self, k: u32) -> Option<Self>
where Self: Sized;
fn digits(&self) -> Self;
}
Required Methods§
Sourcefn permutation(&self, k: u32) -> Self
fn permutation(&self, k: u32) -> Self
Calculates k-permutations.
§Examples
Basic usage:
let n: u32 = 6;
assert_eq!(n.permutation(3), 120);
Sourcefn combination(&self, k: u32) -> Self
fn combination(&self, k: u32) -> Self
Sourcefn gcd(&self, m: Self) -> Self
fn gcd(&self, m: Self) -> Self
Calculates greatest common divisor of two integers.
§Examples
Basic usage:
let n: u32 = 54;
assert_eq!(n.gcd(24), 6);
Sourcefn lcm(&self, m: Self) -> Self
fn lcm(&self, m: Self) -> Self
Calculates least common multiple.
§Examples
Basic usage:
let n: u32 = 72;
assert_eq!(n.lcm(10), 360);
Sourcefn checked_factorial(&self) -> Option<Self>where
Self: Sized,
fn checked_factorial(&self) -> Option<Self>where
Self: Sized,
Calculates factorial, returning None if overflow occured.
§Examples
Basic usage:
let n: u32 = 5;
assert_eq!(n.checked_factorial(), Some(120));
assert_eq!(u32::MAX.checked_factorial(), None);
Sourcefn checked_permutation(&self, k: u32) -> Option<Self>where
Self: Sized,
fn checked_permutation(&self, k: u32) -> Option<Self>where
Self: Sized,
Calculates k-permutations, returning None if overflow occured.
§Examples
Basic usage:
let n: u32 = 6;
assert_eq!(n.checked_permutation(3), Some(120));
assert_eq!(u32::MAX.checked_permutation(3), None);
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.