Struct metriken::Gauge

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

A gauge. Indicates the current value of some host parameter.

In case of overflow/underflow the gauge will wrap around. However, internally it uses a signed 64-bit integer so for most use cases this should be unlikely.

§Example

#[metric(name = "my.gauge")]
static A_METHOD_RUNNING: Gauge = Gauge::new();

fn a_method() {
    A_METHOD_RUNNING.increment();
    // ...
    A_METHOD_RUNNING.decrement();
}

Implementations§

source§

impl Gauge

source

pub const fn new() -> Self

Create a new guage with the default value of 0.

source

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

Create a new guage with the provided initial value.

source

pub fn increment(&self) -> i64

Increment the value of this gauge by 1.

Returns the old value of the gauge.

source

pub fn decrement(&self) -> i64

Decrement the value of this gauge by 1.

Returns the old value of the gauge.

source

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

Increase the value of this gauge by value.

Returns the od value of the gauge.

source

pub fn sub(&self, value: i64) -> i64

Decrease the value of this gauge by value.

Returns the od value of the gauge.

source

pub fn value(&self) -> i64

source

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

source

pub fn reset(&self) -> i64

Trait Implementations§

source§

impl Debug for Gauge

source§

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

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

impl Default for Gauge

source§

fn default() -> Gauge

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

impl Metric for Gauge

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§

§

impl !Freeze for Gauge

§

impl RefUnwindSafe for Gauge

§

impl Send for Gauge

§

impl Sync for Gauge

§

impl Unpin for Gauge

§

impl UnwindSafe for Gauge

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.