bitstream_io

Trait Numeric

Source
pub trait Numeric:
    Primitive
    + Sized
    + Copy
    + Default
    + Debug
    + PartialOrd
    + Shl<u32, Output = Self>
    + ShlAssign<u32>
    + Shr<u32, Output = Self>
    + ShrAssign<u32>
    + Rem<Self, Output = Self>
    + RemAssign<Self>
    + BitOrAssign<Self>
    + BitXor<Self, Output = Self>
    + Not<Output = Self>
    + Sub<Self, Output = Self> {
    const BITS_SIZE: u32;
    const ONE: Self;

    // Required methods
    fn is_zero(self) -> bool;
    fn from_u8(u: u8) -> Self;
    fn to_u8(self) -> u8;
    fn count_ones(self) -> u32;
    fn leading_zeros(self) -> u32;
    fn trailing_zeros(self) -> u32;
    fn unsigned_value(self) -> UnsignedValue;
}
Expand description

This trait extends many common integer types (both unsigned and signed) with a few trivial methods so that they can be used with the bitstream handling traits.

Required Associated Constants§

Source

const BITS_SIZE: u32

Size of type in bits

Source

const ONE: Self

The value of 1 in this type

Required Methods§

Source

fn is_zero(self) -> bool

Returns true if this value is 0, in its type

Source

fn from_u8(u: u8) -> Self

Returns a u8 value in this type

Source

fn to_u8(self) -> u8

Assuming 0 <= value < 256, returns this value as a u8 type

Source

fn count_ones(self) -> u32

Counts the number of 1 bits

Source

fn leading_zeros(self) -> u32

Counts the number of leading zeros

Source

fn trailing_zeros(self) -> u32

Counts the number of trailing zeros

Source

fn unsigned_value(self) -> UnsignedValue

Convert to a generic unsigned write value for stream recording purposes

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 Numeric for i8

Source§

const BITS_SIZE: u32 = 8u32

Source§

const ONE: Self = 1i8

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for i16

Source§

const BITS_SIZE: u32 = 16u32

Source§

const ONE: Self = 1i16

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for i32

Source§

const BITS_SIZE: u32 = 32u32

Source§

const ONE: Self = 1i32

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for i64

Source§

const BITS_SIZE: u32 = 64u32

Source§

const ONE: Self = 1i64

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for i128

Source§

const BITS_SIZE: u32 = 128u32

Source§

const ONE: Self = 1i128

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for u8

Source§

const BITS_SIZE: u32 = 8u32

Source§

const ONE: Self = 1u8

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for u16

Source§

const BITS_SIZE: u32 = 16u32

Source§

const ONE: Self = 1u16

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for u32

Source§

const BITS_SIZE: u32 = 32u32

Source§

const ONE: Self = 1u32

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for u64

Source§

const BITS_SIZE: u32 = 64u32

Source§

const ONE: Self = 1u64

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Source§

impl Numeric for u128

Source§

const BITS_SIZE: u32 = 128u32

Source§

const ONE: Self = 1u128

Source§

fn is_zero(self) -> bool

Source§

fn from_u8(u: u8) -> Self

Source§

fn to_u8(self) -> u8

Source§

fn count_ones(self) -> u32

Source§

fn leading_zeros(self) -> u32

Source§

fn trailing_zeros(self) -> u32

Source§

fn unsigned_value(self) -> UnsignedValue

Implementors§