Trait metrics::CounterFn

source ·
pub trait CounterFn {
    // Required methods
    fn increment(&self, value: u64);
    fn absolute(&self, value: u64);
}
Expand description

A counter handler.

Required Methods§

source

fn increment(&self, value: u64)

Increments the counter by the given amount.

Returns the previous value.

source

fn absolute(&self, value: u64)

Sets the counter to at least the given amount.

This is intended to support use cases where multiple callers are attempting to synchronize this counter with an external counter that they have no control over. As multiple callers may read that external counter, and attempt to set it here, there could be reordering issues where a caller attempts to set an older (smaller) value after the counter has been updated to the latest (larger) value.

This method must cope with those cases. An example of doing so atomically can be found in AtomicCounter.

Returns the previous value.

Implementations on Foreign Types§

source§

impl CounterFn for AtomicU64

source§

fn increment(&self, value: u64)

source§

fn absolute(&self, value: u64)

source§

impl<T> CounterFn for Arc<T>where T: CounterFn,

source§

fn increment(&self, value: u64)

source§

fn absolute(&self, value: u64)

Implementors§