pub struct Percent(/* private fields */);Expand description
A percentage value in 0.0..=100.0.
Eq / Hash are deliberately not implemented (float comparison).
Implementations§
Source§impl Percent
impl Percent
pub const ZERO: Self
pub const HUNDRED: Self
Sourcepub fn from_fraction(f: f64) -> Self
pub fn from_fraction(f: f64) -> Self
Construct from a fraction in [0, 1]. Percent::from_fraction(0.5) == 50%.
Sourcepub const fn as_percent(self) -> f64
pub const fn as_percent(self) -> f64
Get the percentage as f64 in [0, 100].
Sourcepub fn as_fraction(self) -> f64
pub fn as_fraction(self) -> f64
Get the percentage as a fraction in [0, 1].
Sourcepub fn as_kernel_probability(self) -> u32
pub fn as_kernel_probability(self) -> u32
Convert to the kernel’s 32-bit probability representation
(used in netem qopt fields). Percent::HUNDRED -> u32::MAX.
Trait Implementations§
Source§impl PartialOrd for Percent
impl PartialOrd for Percent
impl Copy for Percent
impl StructuralPartialEq for Percent
Auto Trait Implementations§
impl Freeze for Percent
impl RefUnwindSafe for Percent
impl Send for Percent
impl Sync for Percent
impl Unpin for Percent
impl UnsafeUnpin for Percent
impl UnwindSafe for Percent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more