pub struct History<T> { /* private fields */ }
Expand description

This struct tracks recent values of some time series.

It can be used as a smoothing filter for e.g. latency, fps etc, or to show a log or graph of recent events.

It has a minimum and maximum length, as well as a maximum storage time.

  • The minimum length is to ensure you have enough data for an estimate.
  • The maximum length is to make sure the history doesn’t take up too much space.
  • The maximum age is to make sure the estimate isn’t outdated.

Time difference between values can be zero, but never negative.

This can be used for things like smoothed averages (for e.g. FPS) or for smoothed velocity (e.g. mouse pointer speed). All times are in seconds.

Implementations

Example:

// Drop events that are older than one second,
// as long we keep at least two events. Never keep more than a hundred events.
let mut history = History::new(2..100, 1.0);
assert_eq!(history.average(), None);
history.add(now(), 40.0_f32);
history.add(now(), 44.0_f32);
assert_eq!(history.average(), Some(42.0));

Current number of values kept in history

Total number of values seen. Includes those that have been discarded due to max_len or max_age.

Amount of time contained from start to end in this History.

(time, value) pairs Time difference between values can be zero, but never negative.

Values must be added with a monotonically increasing time, or at least not decreasing.

Mean time difference between values in this History.

Remove samples that are too old.

Average times rate. If you are keeping track of individual sizes of things (e.g. bytes), this will estimate the bandwidth (bytes per second).

Calculate a smooth velocity (per second) over the entire time span. Calculated as the last value minus the first value over the elapsed time between them.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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