pub struct Percent(/* private fields */);Expand description
A non-negative, finite percentage.
Deliberately not clamped to 0..=100: process CPU under the default
"core" normalization legitimately exceeds 100% for a multi-threaded
process (§8.3). Meters that need a bounded value call
Percent::clamped_to_100.
Implementations§
Source§impl Percent
impl Percent
Sourcepub fn new(value: f32) -> Option<Self>
pub fn new(value: f32) -> Option<Self>
Builds a percentage, rejecting NaN, infinities, and negative values.
Returning None rather than clamping is intentional: a NaN percentage
means the calculation was wrong, and §4 forbids silently converting an
unavailable value to a number.
Sourcepub fn ratio(part: u64, whole: u64) -> Option<Self>
pub fn ratio(part: u64, whole: u64) -> Option<Self>
Builds a percentage from a part / whole ratio.
Returns None when whole is zero, because “0 of 0” has no defined
utilization and must be reported as unavailable rather than as 0%.
Sourcepub fn clamped_to_100(self) -> Self
pub fn clamped_to_100(self) -> Self
Clamps into 0.0..=100.0 for bar and meter rendering.
Sourcepub fn points_from(self, other: Self) -> f32
pub fn points_from(self, other: Self) -> f32
Difference in percentage points, which may be negative.