Debian Codegraph @

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

raw
1 # Bit-wise `memset`
2
3 This fills a region of memory with a bit value. It is equivalent to using
4 `memset` with only `!0` or `0`, masked appropriately for the region edges.
5
6 ## Original
7
8 [`ptr::write_bytes`](core::ptr::write_bytes)
9
10 ## Safety
11
12 Because this performs a dereference of memory, it inherits the original
13 `ptr::write_bytes`’ requirements:
14
15 - `dst` must be valid to write
16 - `dst` must be properly aligned. This is an invariant of the `BitPtr` type as
17 well as of the memory access.
18
19 Additionally, `dst` must point to an initialized value of `T`. Integers cannot
20 be initialized one bit at a time.
21
22 ## Behavior
23
24 This function does not specify an implementation. You should assume the worst
25 case (`O(n)` read/modify/write of each bit). The [`BitSlice::fill`][0] method
26 will have equal or better performance.
27
28 ## Examples
29
30 ```rust
31 use bitvec::prelude::*;
32 use bitvec::ptr as bv_ptr;
33
34 let mut data = 0u8;
35 let ptr = BitPtr::<_, _, Lsb0>::from_mut(&mut data);
36 unsafe {
37 bv_ptr::write_bits(ptr.add(1), true, 5);
38 }
39 assert_eq!(data, 0b0011_1110);
40 ```
41
42 [0]: crate::slice::BitSlice::fill