Debian Codegraph @

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

raw
1 # Single-Bit Volatile Read
2
3 This reads the bit out of `src` directly, using a volatile I/O intrinsic to
4 prevent compiler reördering or removal.
5
6 You should not use `bitvec` to perform any volatile I/O operations. You should
7 instead do volatile I/O work on integer values directly, or use a crate like
8 [`voladdress`][0] to perform I/O transactions, and use `bitvec` only on stack
9 locals that have no additional memory semantics.
10
11 ## Original
12
13 [`ptr::read_volatile`](core::ptr::read_volatile)
14
15 ## Safety
16
17 Because this performs a dereference of memory, it inherits the original
18 `ptr::read_volatile`’s requirements:
19
20 - `src` must be valid to read.
21 - `src` must be properly aligned. This is an invariant of the `BitPtr` type as
22 well as of the memory access.
23 - `src` must point to an initialized value of `T`.
24
25 Remember that volatile accesses are ordinary loads that the compiler cannot
26 remove or reörder! They are *not* an atomic synchronizer.
27
28 ## Examples
29
30 ```rust
31 use bitvec::prelude::*;
32 use bitvec::ptr as bv_ptr;
33
34 let data = 128u8;
35 let ptr = BitPtr::<_, _, Msb0>::from_ref(&data);
36 assert!(unsafe { bv_ptr::read_volatile(ptr) });
37 ```
38
39 [0]: https://docs.rs/voladdress/latest/voladdress