pub struct RateEstimator {
accum_bytes: f64,
accum_secs: f64,
prev_bytes: Option<u64>,
prev_at: Instant,
smoothed_eta: Option<f64>,
}Expand description
Time-decayed estimate of download throughput and time remaining.
Feed it cumulative byte counts with record — on every
tick, including ticks where the count has not changed, since those are what
make a stalled transfer decay toward zero.
Fields§
§accum_bytes: f64Decayed sum of bytes transferred.
accum_secs: f64Decayed sum of elapsed time, in seconds.
prev_bytes: Option<u64>Cumulative byte count at the previous sample; None before the first.
prev_at: InstantTimestamp of the previous sample.
smoothed_eta: Option<f64>Smoothed seconds remaining; None when unknown or complete.
Implementations§
Source§impl RateEstimator
impl RateEstimator
Sourcepub fn record(&mut self, downloaded: u64, total: u64, now: Instant)
pub fn record(&mut self, downloaded: u64, total: u64, now: Instant)
Record a cumulative byte count.
downloaded and total are cumulative totals for the whole artifact,
not per-tick deltas. total may be 0 when the size is not yet known,
in which case no ETA is produced.
Call this on every tick of the progress bridge. Ticks where downloaded
has not moved are meaningful samples: they are how a stall pulls the
reported rate down.
Sourcepub fn rate_bps(&self) -> Option<f64>
pub fn rate_bps(&self) -> Option<f64>
Current throughput in bytes per second.
None until enough time has been observed for the average to mean
anything — callers should render a placeholder rather than a zero.
Sourcepub const fn eta_seconds(&self) -> Option<f64>
pub const fn eta_seconds(&self) -> Option<f64>
Smoothed estimate of the seconds remaining.
None when the total size is unknown, the transfer is complete, or no
rate has been established yet.
Sourcefn update_eta(&mut self, downloaded: u64, total: u64, dt: f64)
fn update_eta(&mut self, downloaded: u64, total: u64, dt: f64)
Fold the latest raw ETA into the smoothed 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