Trait Counter

Source
pub trait Counter:
    Default
    + Sized
    + From<u8>
    + TryFrom<u32>
    + TryFrom<usize> {
    // Required methods
    fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>;
    fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>;
    fn byte_aligned(&self) -> bool;
}
Expand description

A common trait for integer types for performing math operations which may check for overflow.

Required Methods§

Source

fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>

add rhs to self, returning Overflowed if the result is too large

Source

fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>

multiply self by rhs, returning Overflowed if the result is too large

Source

fn byte_aligned(&self) -> bool

returns true if the number if bits written is divisible by 8

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Counter for u8

Source§

fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>

Source§

fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>

Source§

fn byte_aligned(&self) -> bool

Source§

impl Counter for u16

Source§

fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>

Source§

fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>

Source§

fn byte_aligned(&self) -> bool

Source§

impl Counter for u32

Source§

fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>

Source§

fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>

Source§

fn byte_aligned(&self) -> bool

Source§

impl Counter for u64

Source§

fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>

Source§

fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>

Source§

fn byte_aligned(&self) -> bool

Source§

impl Counter for u128

Source§

fn checked_add_assign(&mut self, rhs: Self) -> Result<(), Overflowed>

Source§

fn checked_mul(self, rhs: Self) -> Result<Self, Overflowed>

Source§

fn byte_aligned(&self) -> bool

Implementors§