Trait bitvec::Bits [−][src]
pub trait Bits: Sealed + Binary + BitAnd<Self, Output = Self> + BitAndAssign<Self> + BitOrAssign<Self> + Copy + Debug + Default + Display + Eq + From<u8> + LowerHex + Not<Output = Self> + Shl<u8, Output = Self> + ShlAssign<u8> + Shr<u8, Output = Self> + ShrAssign<u8> + Sized + UpperHex { const WIDTH: u8; const BITS: u8; const MASK: u8; const MAX_ELT: usize; fn ones(&self) -> u32; fn zeros(&self) -> u32; fn set(&mut self, place: u8, value: bool) { ... } fn get(&self, place: u8) -> bool { ... } fn split(cursor: usize) -> (usize, u8) { ... } fn join(elt: usize, bit: u8) -> usize { ... } }
A trait for types that can be used as direct storage of bits.
This trait must only be implemented on unsigned integer primitives.
The dependency on Sealed, a crate-private trait, ensures that this trait
can only ever be implemented locally, and no downstream crates are able to
implement it on new types.
Associated Constants
const WIDTH: u8
WIDTH: u8 = 1 << <Self>::BITS
The width in bits of this type.
const BITS: u8
The number of bits required to index the type. This is always log2 of the type width.
Incidentally, this can be computed as size_of().trailing_zeroes() once
that becomes a valid constexpr.
const MASK: u8
MASK: u8 = <Self>::WIDTH - 1
The bitmask to turn an arbitrary usize into the bit index. Bit indices are always stored in the lowest bits of an index value.
const MAX_ELT: usize
MAX_ELT: usize = ::std::usize::MAX >> <Self>::BITS
The maximum number of this type that can be held in a BitVec.
Required Methods
fn ones(&self) -> u32
Counts how many bits are set.
fn zeros(&self) -> u32
Counts how many bits are unset.
Provided Methods
fn set(&mut self, place: u8, value: bool)
Set a specific bit in an element to a given value.
fn get(&self, place: u8) -> bool
Get a specific bit in an element.
fn split(cursor: usize) -> (usize, u8)
Splits a usize cursor into an (element, bit) tuple.
The bit component is semantic count, not bit index.
fn join(elt: usize, bit: u8) -> usize
Joins a usize element cursor and u8 bit cursor into a single
usize cursor.
Implementations on Foreign Types
impl Bits for u8[src]
impl Bits for u8const BITS: u8
fn ones(&self) -> u32[src]
fn ones(&self) -> u32fn zeros(&self) -> u32[src]
fn zeros(&self) -> u32const TY: &'static str
const WIDTH: u8
const MASK: u8
const MAX_ELT: usize
fn set(&mut self, place: u8, value: bool)[src]
fn set(&mut self, place: u8, value: bool)fn get(&self, place: u8) -> bool[src]
fn get(&self, place: u8) -> boolfn split(cursor: usize) -> (usize, u8)[src]
fn split(cursor: usize) -> (usize, u8)fn join(elt: usize, bit: u8) -> usize[src]
fn join(elt: usize, bit: u8) -> usizeimpl Bits for u16[src]
impl Bits for u16const BITS: u8
fn ones(&self) -> u32[src]
fn ones(&self) -> u32fn zeros(&self) -> u32[src]
fn zeros(&self) -> u32const TY: &'static str
const WIDTH: u8
const MASK: u8
const MAX_ELT: usize
fn set(&mut self, place: u8, value: bool)[src]
fn set(&mut self, place: u8, value: bool)fn get(&self, place: u8) -> bool[src]
fn get(&self, place: u8) -> boolfn split(cursor: usize) -> (usize, u8)[src]
fn split(cursor: usize) -> (usize, u8)fn join(elt: usize, bit: u8) -> usize[src]
fn join(elt: usize, bit: u8) -> usizeimpl Bits for u32[src]
impl Bits for u32const BITS: u8
fn ones(&self) -> u32[src]
fn ones(&self) -> u32fn zeros(&self) -> u32[src]
fn zeros(&self) -> u32const TY: &'static str
const WIDTH: u8
const MASK: u8
const MAX_ELT: usize
fn set(&mut self, place: u8, value: bool)[src]
fn set(&mut self, place: u8, value: bool)fn get(&self, place: u8) -> bool[src]
fn get(&self, place: u8) -> boolfn split(cursor: usize) -> (usize, u8)[src]
fn split(cursor: usize) -> (usize, u8)fn join(elt: usize, bit: u8) -> usize[src]
fn join(elt: usize, bit: u8) -> usizeimpl Bits for u64[src]
impl Bits for u64const BITS: u8
fn ones(&self) -> u32[src]
fn ones(&self) -> u32fn zeros(&self) -> u32[src]
fn zeros(&self) -> u32const TY: &'static str
const WIDTH: u8
const MASK: u8
const MAX_ELT: usize
fn set(&mut self, place: u8, value: bool)[src]
fn set(&mut self, place: u8, value: bool)fn get(&self, place: u8) -> bool[src]
fn get(&self, place: u8) -> boolfn split(cursor: usize) -> (usize, u8)[src]
fn split(cursor: usize) -> (usize, u8)fn join(elt: usize, bit: u8) -> usize[src]
fn join(elt: usize, bit: u8) -> usize