Struct Counter

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

A counter with current and maximum tracking, and optional merging behavior.

Implementations§

Source§

impl Counter

Source

pub fn new() -> Self

Creates a new Counter with zeroed values and StatsMergeMode::None.

§Example
let c = rmqtt_utils::Counter::new();
Source

pub fn new_with(c: isize, max: isize, m: StatsMergeMode) -> Self

Creates a new Counter with specified values.

§Example
let c = rmqtt_utils::Counter::new_with(5, 10, rmqtt_utils::StatsMergeMode::Sum);
Source

pub fn inc(&self)

Increments current count by 1 and updates max if needed.

§Example
let c = rmqtt_utils::Counter::new();
c.inc();
Source

pub fn incs(&self, c: isize)

Increments current count by c and updates max if needed.

§Example
let c = rmqtt_utils::Counter::new();
c.incs(5);
Source

pub fn current_inc(&self)

Increments current count by 1 without affecting max.

§Example
let c = rmqtt_utils::Counter::new();
c.current_inc();
Source

pub fn current_incs(&self, c: isize)

Increments current count by c without affecting max.

§Example
let c = rmqtt_utils::Counter::new();
c.current_incs(3);
Source

pub fn current_set(&self, c: isize)

Sets the current count directly, does not affect max.

§Example
let c = rmqtt_utils::Counter::new();
c.current_set(100);
Source

pub fn sets(&self, c: isize)

Sets the current count and possibly updates the max.

§Example
let c = rmqtt_utils::Counter::new();
c.sets(20);
Source

pub fn dec(&self)

Decrements current count by 1.

§Example
let c = rmqtt_utils::Counter::new();
c.dec();
Source

pub fn decs(&self, c: isize)

Decrements current count by c.

§Example
let c = rmqtt_utils::Counter::new();
c.decs(4);
Source

pub fn count_min(&self, count: isize)

Sets current count to the minimum of its current value and count.

§Example
let c = rmqtt_utils::Counter::new();
c.count_min(5);
Source

pub fn count_max(&self, count: isize)

Sets current count to the maximum of its current value and count.

§Example
let c = rmqtt_utils::Counter::new();
c.count_max(10);
Source

pub fn max_max(&self, max: isize)

Sets max to the maximum of its current value and max.

§Example
let c = rmqtt_utils::Counter::new();
c.max_max(50);
Source

pub fn max_min(&self, max: isize)

Sets max to the minimum of its current value and max.

§Example
let c = rmqtt_utils::Counter::new();
c.max_min(30);
Source

pub fn count(&self) -> isize

Returns the current count value.

§Example
let c = rmqtt_utils::Counter::new();
let v = c.count();
Source

pub fn max(&self) -> isize

Returns the current max value.

§Example
let c = rmqtt_utils::Counter::new();
let m = c.max();
Source

pub fn add(&self, other: &Self)

Adds values from another counter.

§Example
let a = rmqtt_utils::Counter::new_with(3, 10, rmqtt_utils::StatsMergeMode::None);
let b = rmqtt_utils::Counter::new_with(2, 5, rmqtt_utils::StatsMergeMode::None);
a.add(&b);
Source

pub fn set(&self, other: &Self)

Replaces internal values with those from another counter.

§Example
let a = rmqtt_utils::Counter::new();
let b = rmqtt_utils::Counter::new_with(5, 100, rmqtt_utils::StatsMergeMode::None);
a.set(&b);
Source

pub fn merge(&self, other: &Self)

Merges another counter into this one using the configured merge mode.

§Example
let a = rmqtt_utils::Counter::new_with(1, 2, rmqtt_utils::StatsMergeMode::Sum);
let b = rmqtt_utils::Counter::new_with(3, 4, rmqtt_utils::StatsMergeMode::Sum);
a.merge(&b);
Source

pub fn to_json(&self) -> Value

Converts the counter to JSON format.

§Example
let c = rmqtt_utils::Counter::new();
let json = c.to_json();

Trait Implementations§

Source§

impl Clone for Counter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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() -> Self

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

impl<'de> Deserialize<'de> for Counter

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Counter

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,