| 1 |
# Bit View |
| 2 |
|
| 3 |
This trait describes a region of memory that can be viewed as its constituent |
| 4 |
bits. It is blanket-implemented on all [`BitStore`] implementors, as well as |
| 5 |
slices and arrays of them. It should not be implemented on any other types. |
| 6 |
|
| 7 |
The contained extension methods allow existing memory to be easily viewd as |
| 8 |
[`BitSlice`]s using dot-call method syntax rather than the more cumbersome |
| 9 |
constructor functions in `BitSlice`’s inherent API. |
| 10 |
|
| 11 |
Since the element type is already known to the implementor, the only type |
| 12 |
parameter you need to provide when calling these methods is the bit-ordering. |
| 13 |
|
| 14 |
## Examples |
| 15 |
|
| 16 |
```rust |
| 17 |
use bitvec::prelude::*; |
| 18 |
|
| 19 |
let a = 0u16; |
| 20 |
let a_bits: &BitSlice<u16, Lsb0> = a.view_bits::<Lsb0>(); |
| 21 |
|
| 22 |
let mut b = [0u8; 4]; |
| 23 |
let b_bits: &mut BitSlice<u8, Msb0> = b.view_bits_mut::<Msb0>(); |
| 24 |
``` |
| 25 |
|
| 26 |
[`BitSlice`]: crate::slice::BitSlice |
| 27 |
[`BitStore`]: crate::store::BitStore |