Struct bv::BitSlice [−][src]
pub struct BitSlice<'a, Block> { /* fields omitted */ }
Expand description
A slice of a bit-vector; akin to &'a [bool]
but packed.
Examples
use bv::*; let array = [0b00110101u16]; let mut slice = array.bit_slice(..8); assert_eq!( slice[0], true ); assert_eq!( slice[1], false ); slice = slice.bit_slice(1..8); assert_eq!( slice[0], false ); assert_eq!( slice[1], true );
Implementations
Creates a BitSlice
from an array slice of blocks.
The size is always a multiple of
Block::nbits()
. If you want a different size, slice.
Examples
use bv::{BitSlice, BitSliceable}; let v = vec![0b01010011u16, 0u16]; let slice = BitSlice::from_slice(&v).bit_slice(..7); assert_eq!( slice.len(), 7 ); assert_eq!( slice[0], true ); assert_eq!( slice[1], true ); assert_eq!( slice[2], false );
Creates a BitSlice
from a pointer to its data, an offset where the bits start, and
the number of available bits.
This is unsafe because the size of the passed-in buffer is
not checked. It must hold at least offset + len
bits or the resulting behavior is
undefined.
Precondition
- the first
Block::ceil_div_nbits(len + offset)
words ofbits
safe to read.
The number of bits in the slice.
Examples
use bv::*; let bv: BitVec = bit_vec![ true, true, false, true ]; let slice = bv.bit_slice(..3); assert_eq!( bv.len(), 4 ); assert_eq!( slice.len(), 3 );
Trait Implementations
Performs the conversion.
Performs the conversion.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<'a, Block> RefUnwindSafe for BitSlice<'a, Block> where
Block: RefUnwindSafe,
impl<'a, Block> UnwindSafe for BitSlice<'a, Block> where
Block: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more