| 1 |
# Single-Bit Replacement |
| 2 |
|
| 3 |
This writes a new value into a location, and returns the bit-value previously |
| 4 |
stored there. It is semantically and behaviorally equivalent to |
| 5 |
[`BitRef::replace`][0], except that it works on bit-pointer structures rather |
| 6 |
than proxy references. Prefer to use a proxy reference or |
| 7 |
[`BitSlice::replace`][1] instead. |
| 8 |
|
| 9 |
## Original |
| 10 |
|
| 11 |
[`ptr::replace`](core::ptr::replace) |
| 12 |
|
| 13 |
## Safety |
| 14 |
|
| 15 |
This has the same safety requirements as [`ptr::read`][2] and [`ptr::write`][3], |
| 16 |
as it is required to use them in its implementation. |
| 17 |
|
| 18 |
## Examples |
| 19 |
|
| 20 |
```rust |
| 21 |
use bitvec::prelude::*; |
| 22 |
use bitvec::ptr as bv_ptr; |
| 23 |
|
| 24 |
let mut data = 4u8; |
| 25 |
let ptr = BitPtr::<_, _, Lsb0>::from_mut(&mut data); |
| 26 |
assert!(unsafe { |
| 27 |
bv_ptr::replace(ptr.add(2), false) |
| 28 |
}); |
| 29 |
assert_eq!(data, 0); |
| 30 |
``` |
| 31 |
|
| 32 |
[0]: crate::ptr::BitRef::replace |
| 33 |
[1]: crate::slice::BitSlice::replace |
| 34 |
[2]: crate::ptr::read |
| 35 |
[3]: crate::ptr::write |