| 1 |
# Single-Bit Read |
| 2 |
|
| 3 |
This reads the bit out of `src` directly. |
| 4 |
|
| 5 |
## Original |
| 6 |
|
| 7 |
[`ptr::read`](core::ptr::read) |
| 8 |
|
| 9 |
## Safety |
| 10 |
|
| 11 |
Because this performs a dereference of memory, it inherits the original |
| 12 |
`ptr::read`’s requirements: |
| 13 |
|
| 14 |
- `src` must be valid to read. |
| 15 |
- `src` must be properly aligned. This is an invariant of the `BitPtr` type as |
| 16 |
well as of the memory access. |
| 17 |
- `src` must point to an initialized value of `T`. |
| 18 |
|
| 19 |
## Examples |
| 20 |
|
| 21 |
```rust |
| 22 |
use bitvec::prelude::*; |
| 23 |
use bitvec::ptr as bv_ptr; |
| 24 |
|
| 25 |
let data = 128u8; |
| 26 |
let ptr = BitPtr::<_, _, Msb0>::from_ref(&data); |
| 27 |
assert!(unsafe { bv_ptr::read(ptr) }); |
| 28 |
``` |