pub struct Counter(/* private fields */);Expand description
A counter with current and maximum tracking, and optional merging behavior.
Implementations§
Source§impl Counter
impl Counter
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Counter with zeroed values and StatsMergeMode::None.
§Example
let c = rmqtt_utils::Counter::new();Sourcepub fn new_with(c: isize, max: isize, m: StatsMergeMode) -> Self
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);Sourcepub fn inc(&self)
pub fn inc(&self)
Increments current count by 1 and updates max if needed.
§Example
let c = rmqtt_utils::Counter::new();
c.inc();Sourcepub fn incs(&self, c: isize)
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);Sourcepub fn current_inc(&self)
pub fn current_inc(&self)
Increments current count by 1 without affecting max.
§Example
let c = rmqtt_utils::Counter::new();
c.current_inc();Sourcepub fn current_incs(&self, c: isize)
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);Sourcepub fn current_set(&self, c: isize)
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);Sourcepub fn sets(&self, c: isize)
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);Sourcepub fn count_min(&self, count: isize)
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);Sourcepub fn count_max(&self, count: isize)
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);Sourcepub fn max_max(&self, max: isize)
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);Sourcepub fn max_min(&self, max: isize)
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);Sourcepub fn add(&self, other: &Self)
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);Sourcepub fn set(&self, other: &Self)
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);