Struct metriken::Counter

source ·
pub struct Counter(/* private fields */);
Expand description

A counter. Can be incremented or added to.

In case of overflow the counter will wrap around. However, internally it uses an unsigned 64-bit integer so for most use cases this should be unlikely.

§Example

#[metric(name = "my.custom.metric")]
static MY_COUNTER: Counter = Counter::new();

fn a_method() {
    MY_COUNTER.increment();
    // ...
}

Implementations§

source§

impl Counter

source

pub const fn new() -> Self

Create a counter initialized to 0.

source

pub const fn with_value(value: u64) -> Self

Create a counter initialized to value.

source

pub fn increment(&self) -> u64

source

pub fn add(&self, value: u64) -> u64

source

pub fn value(&self) -> u64

source

pub fn set(&self, value: u64) -> u64

source

pub fn reset(&self) -> u64

Trait Implementations§

source§

impl Debug for Counter

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Counter

source§

fn default() -> Counter

Returns the “default value” for a type. Read more
source§

impl Metric for Counter

source§

fn as_any(&self) -> Option<&dyn Any>

Get the current metric as an Any instance. This is meant to allow custom processing for known metric types.
source§

fn value(&self) -> Option<Value<'_>>

Get the value of the current metric, should it be enabled. Read more
source§

fn is_enabled(&self) -> bool

Indicate whether this metric has been set up. Read more

Auto Trait Implementations§

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

§

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

§

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.