Skip to main content

HistoryWindow

Struct HistoryWindow 

Source
pub struct HistoryWindow<'a> { /* private fields */ }
Expand description

A ring plus the cursor into it that a rule evaluates against.

Implementations§

Source§

impl<'a> HistoryWindow<'a>

Source

pub const fn new(ring: &'a HistoryRing, view: HistoryView) -> Self

Pairs a ring with an explicit cursor.

Source

pub const fn live(ring: &'a HistoryRing) -> Self

Pairs a ring with a cursor following the newest sample.

Source

pub const fn view(&self) -> HistoryView

The cursor, which is the HistoryView §11.1’s sketch passes.

Source

pub const fn ring(&self) -> &'a HistoryRing

The ring being read.

Source

pub fn expected_interval(&self) -> Duration

The interval history is configured to retain samples at (§8.5).

Rules that need a reference interval use this rather than assuming one second (§8.1).

Source

pub fn selected(&self) -> Option<&'a HistoricalSample>

The sample the cursor selects, or the newest one when live.

Source

pub fn len(&self) -> usize

How many samples are retained in total.

Source

pub fn is_empty(&self) -> bool

Whether no sample has been recorded yet.

Source

pub fn recent( &self, count: usize, ) -> impl DoubleEndedIterator<Item = &'a HistoricalSample>

The count samples ending at the cursor, oldest first.

Resolved by absolute index, so it costs one deque lookup per sample and never scans the ring (§21 M4).

Source

pub fn previous_sample(&self, sequence: u64) -> Option<&'a HistoricalSample>

The newest retained sample strictly older than sequence.

Rules that compare “now” against “the previous sample” use this so they work whether or not the snapshot under evaluation has already been recorded into the ring.

Source

pub fn count_where( &self, metric: HistoryMetric, count: usize, predicate: impl Fn(f64) -> bool, ) -> Counted

Counts how many of the count most recent samples satisfy predicate.

predicate sees only freshly measured values: a sample whose metric was unavailable is tallied in Counted::unavailable and never passed to the predicate, so no rule can accidentally treat a missing reading as a zero (§26).

Source

pub fn count_at_least( &self, metric: HistoryMetric, count: usize, threshold: f64, ) -> Counted

Counts how many of the count most recent samples are at or above threshold.

Source

pub fn trend( &self, metric: HistoryMetric, count: usize, ) -> Option<(f64, f64, Duration)>

The oldest and newest freshly measured values of metric in the window.

Returns None unless both ends were measured, because a trend computed against a missing endpoint is a fabrication (§26). The returned duration is the real span between the two samples, never an assumed one (§8.1).

Trait Implementations§

Source§

impl<'a> Clone for HistoryWindow<'a>

Source§

fn clone(&self) -> HistoryWindow<'a>

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<'a> Copy for HistoryWindow<'a>

Source§

impl<'a> Debug for HistoryWindow<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for HistoryWindow<'a>

§

impl<'a> RefUnwindSafe for HistoryWindow<'a>

§

impl<'a> Send for HistoryWindow<'a>

§

impl<'a> Sync for HistoryWindow<'a>

§

impl<'a> Unpin for HistoryWindow<'a>

§

impl<'a> UnsafeUnpin for HistoryWindow<'a>

§

impl<'a> UnwindSafe for HistoryWindow<'a>

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.

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> 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.