pub trait AsBits {
type Store: BitStore;
fn bits<O>(&self) -> &BitSlice<O, Self::Store>
where
O: BitOrder;
fn bits_mut<O>(&mut self) -> &mut BitSlice<O, Self::Store>
where
O: BitOrder;
}
Expand description
Allows a type to be used as a sequence of immutable bits.
Requirements
This trait can only be implemented by contiguous structures: individual fundamentals, and sequences (arrays or slices) of them.
Associated Types
Required methods
Constructs a BitSlice
reference over data.
Type Parameters
O: BitOrder
: TheBitOrder
type used to index within the slice.
Parameters
&self
Returns
A BitSlice
handle over self
’s data, using the provided BitOrder
type and using Self::Store
as the data type.
Examples
use bitvec::prelude::*;
let src = 8u8;
let bits = src.bits::<Msb0>();
assert!(bits[4]);
Constructs a mutable BitSlice
reference over data.
Type Parameters
O: BitOrder
: TheBitOrder
type used to index within the slice.
Parameters
&mut self
Returns
A BitSlice
handle over self
’s data, using the provided BitOrder
type and using Self::Store
as the data type.
Examples
use bitvec::prelude::*;
let mut src = 8u8;
let bits = src.bits_mut::<Lsb0>();
assert!(bits[3]);
*bits.at(3) = false;
assert!(!bits[3]);