pub struct ByteCounter<D> { /* private fields */ }Expand description
Generic byte counter with compile-time direction tracking via phantom types
This zero-cost abstraction provides type-safe byte counting where the direction
is encoded in the type system. The PhantomData<D> has zero size at runtime.
Implementations§
Source§impl<D> ByteCounter<D>
impl<D> ByteCounter<D>
pub const ZERO: Self
pub const fn new(bytes: u64) -> Self
pub const fn zero() -> Self
pub const fn as_u64(&self) -> u64
pub const fn add(self, bytes: usize) -> Self
pub const fn add_u64(self, bytes: u64) -> Self
pub const fn saturating_sub(self, other: Self) -> Self
Trait Implementations§
Source§impl<D> Add for ByteCounter<D>
impl<D> Add for ByteCounter<D>
Source§impl<D> AddAssign for ByteCounter<D>
impl<D> AddAssign for ByteCounter<D>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl<D: Clone> Clone for ByteCounter<D>
impl<D: Clone> Clone for ByteCounter<D>
Source§fn clone(&self) -> ByteCounter<D>
fn clone(&self) -> ByteCounter<D>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<D: Copy> Copy for ByteCounter<D>
Source§impl<D: Debug> Debug for ByteCounter<D>
impl<D: Debug> Debug for ByteCounter<D>
Source§impl<D: Default> Default for ByteCounter<D>
impl<D: Default> Default for ByteCounter<D>
Source§fn default() -> ByteCounter<D>
fn default() -> ByteCounter<D>
Returns the “default value” for a type. Read more
Source§impl<'de, D> Deserialize<'de> for ByteCounter<D>
impl<'de, D> Deserialize<'de> for ByteCounter<D>
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
Source§impl<D> Display for ByteCounter<D>
impl<D> Display for ByteCounter<D>
impl<D: Eq> Eq for ByteCounter<D>
Source§impl<D> From<ByteCounter<D>> for u64
impl<D> From<ByteCounter<D>> for u64
Source§fn from(counter: ByteCounter<D>) -> Self
fn from(counter: ByteCounter<D>) -> Self
Converts to this type from the input type.
Source§impl<D> From<u64> for ByteCounter<D>
impl<D> From<u64> for ByteCounter<D>
Source§impl<D: Ord> Ord for ByteCounter<D>
impl<D: Ord> Ord for ByteCounter<D>
Source§fn cmp(&self, other: &ByteCounter<D>) -> Ordering
fn cmp(&self, other: &ByteCounter<D>) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<D: PartialEq> PartialEq for ByteCounter<D>
impl<D: PartialEq> PartialEq for ByteCounter<D>
Source§impl<D: PartialOrd> PartialOrd for ByteCounter<D>
impl<D: PartialOrd> PartialOrd for ByteCounter<D>
Source§impl<D> Serialize for ByteCounter<D>
impl<D> Serialize for ByteCounter<D>
impl<D: PartialEq> StructuralPartialEq for ByteCounter<D>
Auto Trait Implementations§
impl<D> Freeze for ByteCounter<D>where
PhantomData<D>: Freeze,
impl<D> RefUnwindSafe for ByteCounter<D>where
PhantomData<D>: RefUnwindSafe,
impl<D> Send for ByteCounter<D>where
PhantomData<D>: Send,
impl<D> Sync for ByteCounter<D>where
PhantomData<D>: Sync,
impl<D> Unpin for ByteCounter<D>where
PhantomData<D>: Unpin,
impl<D> UnsafeUnpin for ByteCounter<D>where
PhantomData<D>: UnsafeUnpin,
impl<D> UnwindSafe for ByteCounter<D>where
PhantomData<D>: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Code for Twhere
T: Serialize + DeserializeOwned,
impl<T> Code for Twhere
T: Serialize + DeserializeOwned,
Source§fn encode(&self, writer: &mut impl Write) -> Result<(), Error>
fn encode(&self, writer: &mut impl Write) -> Result<(), Error>
Encode the object into a writer. Read more
Source§fn decode(reader: &mut impl Read) -> Result<T, Error>
fn decode(reader: &mut impl Read) -> Result<T, Error>
Decode the object from a reader. Read more
Source§fn estimated_size(&self) -> usize
fn estimated_size(&self) -> usize
Estimated serialized size of the object. Read more
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> StorageValue for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more