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>
impl<T> Delta<T>
Sourcepub fn new(start: Option<Timestamp>, initial: T) -> Self
pub fn new(start: Option<Timestamp>, initial: T) -> Self
Create a new delta container with an initial timestamp and value.
Sourcepub fn new_default(start: Option<Timestamp>) -> Selfwhere
T: Default,
pub fn new_default(start: Option<Timestamp>) -> Selfwhere
T: Default,
Create a new delta container with an initial timestamp and default value.
Sourcepub fn current_start(&self) -> Option<&Timestamp>
pub fn current_start(&self) -> Option<&Timestamp>
Get a reference to the start of the current time period.
Sourcepub fn current_value_mut(&mut self) -> &mut T
pub fn current_value_mut(&mut self) -> &mut T
Get exclusive access to the value of the current time period.
Sourcepub fn current_value(&self) -> &T
pub fn current_value(&self) -> &T
Get shared access to the value of the current time period.
Sourcepub fn advance(&mut self, end: Option<Timestamp>) -> (Option<Extent>, &mut T)
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.
Sourcepub fn advance_default(&mut self, end: Option<Timestamp>) -> (Option<Extent>, T)where
T: Default,
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.