pub struct Percent { /* private fields */ }Expand description
An exact decimal percentage, used for thresholds that are compared with count ratios.
"95.5" is stored as 955 × 10⁻¹, and Percent::is_met_by compares
count / total × 100 ≥ value in exact integer arithmetic, so a threshold never misses its
boundary through floating-point rounding.
Implementations§
Source§impl Percent
impl Percent
Sourcepub const MAX_DECIMALS: u32 = 9
pub const MAX_DECIMALS: u32 = 9
Maximum number of decimal places accepted.
Sourcepub fn is_met_by(self, count: u64, total: u64) -> bool
pub fn is_met_by(self, count: u64, total: u64) -> bool
true when count / total × 100 ≥ self; false when total is 0.
Sourcepub fn hcs_threshold(text: &str) -> Result<Self>
pub fn hcs_threshold(text: &str) -> Result<Self>
Parses an HCS threshold: a decimal in (50, 100].
§Errors
A usage error explaining the range when the text is not a decimal in (50, 100].
Sourcepub fn check_hcs_range(self) -> Result<()>
pub fn check_hcs_range(self) -> Result<()>
Checks that an HCS threshold lies in (50, 100].
§Errors
A usage error with the rationale when out of range.
Trait Implementations§
impl Copy for Percent
Source§impl<'de> Deserialize<'de> for Percent
impl<'de> Deserialize<'de> for Percent
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Percent
Source§impl Ord for Percent
impl Ord for Percent
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Percent
impl PartialOrd 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more