pub struct RateEstimator { /* private fields */ }Expand description
Rolling window of (timestamp, cumulative bytes) observations.
Implementations§
Source§impl RateEstimator
impl RateEstimator
pub fn new() -> Self
Sourcepub fn observe(&mut self, at_ms: u64, bytes: u64)
pub fn observe(&mut self, at_ms: u64, bytes: u64)
Records a cumulative byte count seen at at_ms (any monotonic
millisecond clock; only differences matter).
Two inputs are rejected rather than trusted: a sample older than the newest one (a non-monotonic clock would otherwise produce a negative span), and a byte count below the newest one, which means the transfer restarted – averaging across that discontinuity would report a rate that never happened, so the window is cleared and measurement starts over.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clears the window; the next report is warming again. For a job
that pauses, where the elapsed idle time would otherwise be
charged against the rate.
Sourcepub fn bytes_done(&self) -> Option<u64>
pub fn bytes_done(&self) -> Option<u64>
Latest observed cumulative byte count, if any.
Sourcepub fn report(&self, total_bytes: Option<u64>) -> RateReport
pub fn report(&self, total_bytes: Option<u64>) -> RateReport
total_bytes is optional because plenty of real downloads have
no Content-Length; without it there is a rate but no ETA, and
the UI should show exactly that rather than a fabricated one.
Trait Implementations§
Source§impl Clone for RateEstimator
impl Clone for RateEstimator
Source§fn clone(&self) -> RateEstimator
fn clone(&self) -> RateEstimator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more