Struct s2n_quic_core::counter::Counter
source · pub struct Counter<T, Behavior = ()>(/* private fields */);
Expand description
A checked-overflow counter
Rather than silently wrapping, we want to ensure counting errors stay somewhat isolated so the counter will saturate rather than wrap. The counter operates in 3 modes:
- If
debug_assertions
are enabled, the counter will panic on overflow - If the
checked-counters
feature flag is defined, the counter will panic on overflow, even in release builds. - Otherwise, the counter will saturate
The counter can also be configured to always saturate by passing the Saturating
behavior:
use s2n_quic_core::counter::{Counter, Saturating};
let counter: Counter<u32, Saturating> = Default::default();
Implementations§
Trait Implementations§
source§impl<T, R> AddAssign<R> for Counter<T, ()>
impl<T, R> AddAssign<R> for Counter<T, ()>
source§fn add_assign(&mut self, rhs: R)
fn add_assign(&mut self, rhs: R)
Performs the
+=
operation. Read moresource§impl<T, R> AddAssign<R> for Counter<T, Saturating>where
T: SaturatingAddAssign<R>,
impl<T, R> AddAssign<R> for Counter<T, Saturating>where
T: SaturatingAddAssign<R>,
source§fn add_assign(&mut self, rhs: R)
fn add_assign(&mut self, rhs: R)
Performs the
+=
operation. Read moresource§impl<T, R> MulAssign<R> for Counter<T, ()>
impl<T, R> MulAssign<R> for Counter<T, ()>
source§fn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
Performs the
*=
operation. Read moresource§impl<T, R> MulAssign<R> for Counter<T, Saturating>where
T: SaturatingMulAssign<R>,
impl<T, R> MulAssign<R> for Counter<T, Saturating>where
T: SaturatingMulAssign<R>,
source§fn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
Performs the
*=
operation. Read moresource§impl<T, B> Ord for Counter<T, B>where
T: Ord,
impl<T, B> Ord for Counter<T, B>where
T: Ord,
source§impl<T, B, R> PartialEq<R> for Counter<T, B>where
Self: PartialOrd<R>,
impl<T, B, R> PartialEq<R> for Counter<T, B>where
Self: PartialOrd<R>,
source§impl<T, B> PartialOrd<T> for Counter<T, B>where
T: PartialOrd<T>,
impl<T, B> PartialOrd<T> for Counter<T, B>where
T: PartialOrd<T>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T, B> PartialOrd for Counter<T, B>where
T: PartialOrd<T>,
impl<T, B> PartialOrd for Counter<T, B>where
T: PartialOrd<T>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T, R> SubAssign<R> for Counter<T, ()>
impl<T, R> SubAssign<R> for Counter<T, ()>
source§fn sub_assign(&mut self, rhs: R)
fn sub_assign(&mut self, rhs: R)
Performs the
-=
operation. Read moresource§impl<T, R> SubAssign<R> for Counter<T, Saturating>where
T: SaturatingSubAssign<R>,
impl<T, R> SubAssign<R> for Counter<T, Saturating>where
T: SaturatingSubAssign<R>,
source§fn sub_assign(&mut self, rhs: R)
fn sub_assign(&mut self, rhs: R)
Performs the
-=
operation. Read moresource§impl<T, B> UpcastFrom<&Counter<T, B>> for Twhere
T: for<'a> UpcastFrom<&'a T>,
impl<T, B> UpcastFrom<&Counter<T, B>> for Twhere
T: for<'a> UpcastFrom<&'a T>,
fn upcast_from(value: &Counter<T, B>) -> Self
impl<T: Copy, Behavior: Copy> Copy for Counter<T, Behavior>
impl<T, B> Eq for Counter<T, B>where
Self: Ord,
Auto Trait Implementations§
impl<T, Behavior> Freeze for Counter<T, Behavior>where
T: Freeze,
impl<T, Behavior> RefUnwindSafe for Counter<T, Behavior>where
T: RefUnwindSafe,
Behavior: RefUnwindSafe,
impl<T, Behavior> Send for Counter<T, Behavior>
impl<T, Behavior> Sync for Counter<T, Behavior>
impl<T, Behavior> Unpin for Counter<T, Behavior>
impl<T, Behavior> UnwindSafe for Counter<T, Behavior>where
T: UnwindSafe,
Behavior: UnwindSafe,
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