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