pub struct CounterUsize(/* private fields */);
Expand description
An 64-bit counter, from 0
to usize::MAX
elements.
Implementations§
Source§impl CounterUsize
§methods
impl CounterUsize
§methods
Sourcepub const fn as_primitive(&self) -> usize
pub const fn as_primitive(&self) -> usize
Retuns the inner primitive type.
If the count pointed to nothing, the maximum primitive value will be returned.
Sourcepub const fn as_usize(&self) -> usize
pub const fn as_usize(&self) -> usize
Returns the inner primitive type as a usize
.
If the count is invalid, the maximum primitive value casted to usize will be returned.
Sourcepub const fn as_current_index(&self) -> NonMaxIndexUsize
pub const fn as_current_index(&self) -> NonMaxIndexUsize
Returns a non-max index that points to 1
less than the current count.
If the current count is 0
, the index will point to None
.
Sourcepub const fn as_next_index(&self) -> NonMaxIndexUsize
pub const fn as_next_index(&self) -> NonMaxIndexUsize
Returns a non-max index that points to the current count value.
If the current count is usize::MAX
, the index will point to None
.
Sourcepub fn increment_by(&mut self, increment: usize) -> Result<()>
pub fn increment_by(&mut self, increment: usize) -> Result<()>
Sourcepub const fn incremented(&self) -> Result<Self>
pub const fn incremented(&self) -> Result<Self>
Returns a copy of the counter incremented by 1
.
§Errors
Overflows if the counter would exceed usize::MAX
.
Sourcepub const fn incremented_by(&self, increment: usize) -> Result<Self>
pub const fn incremented_by(&self, increment: usize) -> Result<Self>
Returns a copy of the counter incremented by increment
.
§Errors
Overflows if the counter would exceed usize::MAX
.
Sourcepub fn decrement_by(&mut self, decrement: usize) -> Result<()>
pub fn decrement_by(&mut self, decrement: usize) -> Result<()>
Sourcepub const fn decremented(&self) -> Result<Self>
pub const fn decremented(&self) -> Result<Self>
Returns a copy of the counter decremented by 1
.
§Errors
Underflows if the counter would subceed 0
.
Underflow if the counter would subceed usize::MAX
.
Sourcepub const fn decremented_by(&self, decrement: usize) -> Result<Self>
pub const fn decremented_by(&self, decrement: usize) -> Result<Self>
Returns a copy of the counter decremented by increment
.
§Errors
Underflows if the counter would subceed 0
.
Trait Implementations§
Source§impl Clone for CounterUsize
impl Clone for CounterUsize
Source§fn clone(&self) -> CounterUsize
fn clone(&self) -> CounterUsize
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more