Debian Codegraph @

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

raw
1 # Single-Bit Write
2
3 This writes a bit into `dst` directly.
4
5 ## Original
6
7 [`ptr::write`](core::ptr::write)
8
9 ## Safety
10
11 Because this performs a dereference of memory, it inherits the original
12 `ptr::write`’s requirements:
13
14 - `dst` must be valid to write
15 - `dst` must be properly aligned. This is an invariant of the `BitPtr` type as
16 well as of the memory access.
17
18 Additionally, `dst` must point to an initialized value of `T`. Integers cannot
19 be initialized one bit at a time.
20
21 ## Behavior
22
23 This is required to perform a read/modify/write cycle on the memory location.
24 LLVM *may or may not* emit a bit-write instruction on targets that have them in
25 the ISA, but this is not specified in any way.
26
27 ## Examples
28
29 ```rust
30 use bitvec::prelude::*;
31 use bitvec::ptr as bv_ptr;
32
33 let mut data = 0u8;
34 let ptr = BitPtr::<_, _, Lsb0>::from_mut(&mut data);
35 unsafe { bv_ptr::write(ptr.add(2), true); }
36 assert_eq!(data, 4);
37 ```