Skip to main content

Delta

Struct Delta 

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

A container for tracking delta-encoded metrics.

emit represents delta metrics as Events where the Extent is a range.

Delta tracks the time its value was last sampled along with the current value itself. The value can be accumulated into with Delta::current_value_mut.

At the end of a user-defined time period, the value can be sampled with Delta::advance. When sampled, an Extent between the last sample and the current is returned along with an exclusive reference to the current value. Callers are expected to reset this value for the new time period before their borrow expires.

Delta is not a Source directly, but can be used as the underlying storage in implementations of them.

Implementations§

Source§

impl<T> Delta<T>

Source

pub fn new(start: Option<Timestamp>, initial: T) -> Self

Create a new delta container with an initial timestamp and value.

Source

pub fn new_default(start: Option<Timestamp>) -> Self
where T: Default,

Create a new delta container with an initial timestamp and default value.

Source

pub fn current_start(&self) -> Option<&Timestamp>

Get a reference to the start of the current time period.

Source

pub fn current_value_mut(&mut self) -> &mut T

Get exclusive access to the value of the current time period.

Source

pub fn current_value(&self) -> &T

Get shared access to the value of the current time period.

Source

pub fn advance(&mut self, end: Option<Timestamp>) -> (Option<Extent>, &mut T)

Advance the delta to a new time period.

This method will return a range Extent from Delta::current_start to end along with the current accumulated value. The next time period will start from end.

Callers are responsible for resetting the current value for the new time period.

Source

pub fn advance_default(&mut self, end: Option<Timestamp>) -> (Option<Extent>, T)
where T: Default,

Advance the delta to a new time period.

This method is an alternative to Delta::advance that sets the value for the new time period with its default for you, returning the previously accumulated one.

This method will return a range Extent from Delta::current_start to end along with the current accumulated value. The next time period will start from end.

Auto Trait Implementations§

§

impl<T> Freeze for Delta<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Delta<T>
where T: RefUnwindSafe,

§

impl<T> Send for Delta<T>
where T: Send,

§

impl<T> Sync for Delta<T>
where T: Sync,

§

impl<T> Unpin for Delta<T>
where T: Unpin,

§

impl<T> UnwindSafe for Delta<T>
where T: UnwindSafe,

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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V