Skip to main content

RateEstimator

Struct RateEstimator 

Source
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: f64

Decayed sum of bytes transferred.

§accum_secs: f64

Decayed sum of elapsed time, in seconds.

§prev_bytes: Option<u64>

Cumulative byte count at the previous sample; None before the first.

§prev_at: Instant

Timestamp of the previous sample.

§smoothed_eta: Option<f64>

Smoothed seconds remaining; None when unknown or complete.

Implementations§

Source§

impl RateEstimator

Source

pub const fn new(now: Instant) -> Self

Create an estimator with its baseline at now.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> RateEstimator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RateEstimator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more