Trait BitBlock

Source
pub trait BitBlock:
    ShlAssign<u8>
    + Shr
    + BitOrAssign
    + Copy {
    // Required methods
    fn zero() -> Self;
    fn zero_array<const N: usize>() -> [Self; N];
    unsafe fn set_bit_unchecked(&mut self, idx: usize);
    fn is_zero(self) -> bool;
    fn is_one(self) -> bool;
    fn leading_zeros(self) -> u32;

    // Provided method
    fn set_bit(&mut self, idx: usize) { ... }
}
Expand description

A trait abstracting over types which can be used as a block of bits.

At the moment this is unsigned integer primitive types.

The trait is not sealed, so you may implement it, but it unstable and may change.

Required Methods§

Source

fn zero() -> Self

The zero value for this type

Source

fn zero_array<const N: usize>() -> [Self; N]

An array of zero values for this type

Source

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Set the single bit at idx places from the left to 1.

§Safety

The caller guarantees that idx is less than the number of bits in the type.

Source

fn is_zero(self) -> bool

Is this value zero?

Source

fn is_one(self) -> bool

Is this value one?

Source

fn leading_zeros(self) -> u32

The number of leading zeros in the bit-representation.

Provided Methods§

Source

fn set_bit(&mut self, idx: usize)

The checked version of set_bit_unchecked

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 BitBlock for u8

Source§

fn zero() -> Self

Source§

fn zero_array<const N: usize>() -> [Self; N]

Source§

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Source§

fn is_zero(self) -> bool

Source§

fn is_one(self) -> bool

Source§

fn leading_zeros(self) -> u32

Source§

impl BitBlock for u16

Source§

fn zero() -> Self

Source§

fn zero_array<const N: usize>() -> [Self; N]

Source§

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Source§

fn is_zero(self) -> bool

Source§

fn is_one(self) -> bool

Source§

fn leading_zeros(self) -> u32

Source§

impl BitBlock for u32

Source§

fn zero() -> Self

Source§

fn zero_array<const N: usize>() -> [Self; N]

Source§

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Source§

fn is_zero(self) -> bool

Source§

fn is_one(self) -> bool

Source§

fn leading_zeros(self) -> u32

Source§

impl BitBlock for u64

Source§

fn zero() -> Self

Source§

fn zero_array<const N: usize>() -> [Self; N]

Source§

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Source§

fn is_zero(self) -> bool

Source§

fn is_one(self) -> bool

Source§

fn leading_zeros(self) -> u32

Source§

impl BitBlock for u128

Source§

fn zero() -> Self

Source§

fn zero_array<const N: usize>() -> [Self; N]

Source§

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Source§

fn is_zero(self) -> bool

Source§

fn is_one(self) -> bool

Source§

fn leading_zeros(self) -> u32

Source§

impl BitBlock for usize

Source§

fn zero() -> Self

Source§

fn zero_array<const N: usize>() -> [Self; N]

Source§

unsafe fn set_bit_unchecked(&mut self, idx: usize)

Source§

fn is_zero(self) -> bool

Source§

fn is_one(self) -> bool

Source§

fn leading_zeros(self) -> u32

Implementors§