Struct tor_units::Percentage [−][src]
Expand description
A percentage value represented as a number.
This type wraps an underlying numeric type, and ensures that callers are clear whether they want a fraction, or a percentage.
Implementations
Return this value as a (possibly improper) fraction.
use tor_units::Percentage;
let pct_200 = Percentage::<u8>::new(200);
let pct_100 = Percentage::<u8>::new(100);
let pct_50 = Percentage::<u8>::new(50);
assert_eq!(pct_200.as_fraction(), 2.0);
assert_eq!(pct_100.as_fraction(), 1.0);
assert_eq!(pct_50.as_fraction(), 0.5);
// Note: don't actually compare f64 with ==.
Return this value as a percentage.
use tor_units::Percentage;
let pct_200 = Percentage::<u8>::new(200);
let pct_100 = Percentage::<u8>::new(100);
let pct_50 = Percentage::<u8>::new(50);
assert_eq!(pct_200.as_percent(), 200);
assert_eq!(pct_100.as_percent(), 100);
assert_eq!(pct_50.as_percent(), 50);
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl<T> RefUnwindSafe for Percentage<T> where
T: RefUnwindSafe,
impl<T> Send for Percentage<T> where
T: Send,
impl<T> Sync for Percentage<T> where
T: Sync,
impl<T> Unpin for Percentage<T> where
T: Unpin,
impl<T> UnwindSafe for Percentage<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more