Debian Codegraph @

debian/rust-vendor/bitvec/doc/ptr/read_unaligned.md

raw
1 # Single-Bit Unaligned Read
2
3 This reads the bit out of `src` directly. It uses compiler intrinsics to
4 tolerate an unaligned `T` address. However, because `BitPtr` has a type
5 invariant that addresses are always well-aligned (and non-null), this has no
6 benefit or purpose.
7
8 ## Original
9
10 [`ptr::read_unaligned`](core::ptr::read_unaligned)
11
12 ## Safety
13
14 Because this performs a dereference of memory, it inherits the original
15 `ptr::read_unaligned`’s requirements:
16
17 - `src` must be valid to read.
18 - `src` must point to an initialized value of `T`.
19
20 ## Examples
21
22 ```rust
23 use bitvec::prelude::*;
24 use bitvec::ptr as bv_ptr;
25
26
27 let data = 128u8;
28 let ptr = BitPtr::<_, _, Msb0>::from_ref(&data);
29 assert!(unsafe { bv_ptr::read_unaligned(ptr) });
30 ```