pub struct Rate(/* private fields */);Expand description
A non-negative, finite “units per second” value.
The unit itself (bytes, packets, operations) is implied by the field the rate is stored in. Rates are calculated, so floating point is permitted (§10.4).
A rate can only be constructed from a validated delta: Rate::new
rejects negatives, so a counter reset cannot silently become a huge or
negative rate (§8.2).
Implementations§
Source§impl Rate
impl Rate
Sourcepub fn new(per_second: f64) -> Option<Self>
pub fn new(per_second: f64) -> Option<Self>
Builds a rate, rejecting NaN, infinities, and negative values.
Sourcepub fn from_delta(delta: u64, elapsed: Duration) -> Option<Self>
pub fn from_delta(delta: u64, elapsed: Duration) -> Option<Self>
Builds a rate from a validated non-negative delta and the actual elapsed time.
Never assume a one-second interval: suspend/resume, load, and scheduler
delay all make the real interval variable (§8.1). Returns None when
elapsed is zero or the result is not finite.
Sourcepub const fn per_second(self) -> f64
pub const fn per_second(self) -> f64
The underlying units-per-second value.
Sourcepub fn delta_from(self, other: Self) -> f64
pub fn delta_from(self, other: Self) -> f64
Signed difference against another rate, for comparison columns (§2.5).