pub struct Counter { /* private fields */ }
Expand description
Represents counters.
Implementations§
Source§impl Counter
impl Counter
Sourcepub const fn try_next(self) -> Option<Self>
pub const fn try_next(self) -> Option<Self>
Returns the incremented counter while checking for overflows.
§Note
Since Counter
is Copy
, one can continue using the original counter after calling
this method. So, even if None
is returned, the original counter will not be dropped.
§Examples
use otp_std::Counter;
let counter = Counter::new(0);
let expected = Counter::new(1);
assert_eq!(counter.try_next(), Some(expected));
Returning None
on overflows:
use otp_std::Counter;
let counter = Counter::new(u64::MAX);
assert_eq!(counter.try_next(), None);
Sourcepub const fn next(self) -> Self
pub const fn next(self) -> Self
Returns the incremented counter, panicking on overflows.
§Panics
This method will panic if the counter overflows.
§Examples
use otp_std::Counter;
let counter = Counter::new(0);
let expected = Counter::new(1);
assert_eq!(counter.next(), expected);
Panicking on overflows:
ⓘ
use otp_std::Counter;
let counter = Counter::new(u64::MAX);
counter.next();
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Counter
impl<'de> Deserialize<'de> for Counter
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Counter
impl Eq for Counter
impl StructuralPartialEq for Counter
Auto Trait Implementations§
impl Freeze for Counter
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnwindSafe for Counter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more