Struct s2n_quic_core::counter::Counter
source · [−]pub struct Counter<T, Behavior = ()>(_, _);
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
sourceimpl<T, R> AddAssign<R> for Counter<T, ()>where
T: SaturatingAddAssign<R> + CheckedAddAssign<R> + AddAssign + UpcastFrom<R>,
impl<T, R> AddAssign<R> for Counter<T, ()>where
T: SaturatingAddAssign<R> + CheckedAddAssign<R> + AddAssign + UpcastFrom<R>,
sourcefn add_assign(&mut self, rhs: R)
fn add_assign(&mut self, rhs: R)
Performs the
+=
operation. Read moresourceimpl<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>,
sourcefn add_assign(&mut self, rhs: R)
fn add_assign(&mut self, rhs: R)
Performs the
+=
operation. Read moresourceimpl<T, R> MulAssign<R> for Counter<T, ()>where
T: SaturatingMulAssign<R> + CheckedMulAssign<R> + MulAssign + UpcastFrom<R>,
impl<T, R> MulAssign<R> for Counter<T, ()>where
T: SaturatingMulAssign<R> + CheckedMulAssign<R> + MulAssign + UpcastFrom<R>,
sourcefn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
Performs the
*=
operation. Read moresourceimpl<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>,
sourcefn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
Performs the
*=
operation. Read moresourceimpl<T, B> Ord for Counter<T, B>where
T: Ord,
impl<T, B> Ord for Counter<T, B>where
T: Ord,
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<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>,
sourceimpl<T, B> PartialOrd<Counter<T, B>> for Counter<T, B>where
T: PartialOrd<T>,
impl<T, B> PartialOrd<Counter<T, B>> for Counter<T, B>where
T: PartialOrd<T>,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const 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 moresourceimpl<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>,
sourcefn partial_cmp(&self, other: &T) -> Option<Ordering>
fn partial_cmp(&self, other: &T) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const 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 moresourceimpl<T, R> SubAssign<R> for Counter<T, ()>where
T: SaturatingSubAssign<R> + CheckedSubAssign<R> + SubAssign + UpcastFrom<R>,
impl<T, R> SubAssign<R> for Counter<T, ()>where
T: SaturatingSubAssign<R> + CheckedSubAssign<R> + SubAssign + UpcastFrom<R>,
sourcefn sub_assign(&mut self, rhs: R)
fn sub_assign(&mut self, rhs: R)
Performs the
-=
operation. Read moresourceimpl<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>,
sourcefn sub_assign(&mut self, rhs: R)
fn sub_assign(&mut self, rhs: R)
Performs the
-=
operation. Read moresourceimpl<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> RefUnwindSafe for Counter<T, Behavior>where
Behavior: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, Behavior> Send for Counter<T, Behavior>where
Behavior: Send,
T: Send,
impl<T, Behavior> Sync for Counter<T, Behavior>where
Behavior: Sync,
T: Sync,
impl<T, Behavior> Unpin for Counter<T, Behavior>where
Behavior: Unpin,
T: Unpin,
impl<T, Behavior> UnwindSafe for Counter<T, Behavior>where
Behavior: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more