pub unsafe fn swap<O1, O2, T1, T2>(
x: BitPtr<Mut, O1, T1>,
y: BitPtr<Mut, O2, T2>
) where
O1: BitOrder,
O2: BitOrder,
T1: BitStore,
T2: BitStore,
Expand description
Swaps the values at two mutable locations.
But for the following exception, this function is semantically equivalent to
BitRef::swap
: it operates on raw pointers instead of references. When
references are available, prefer BitRef::swap
.
Original
Safety
Behavior is undefined if any of the following conditions are violated:
- Both
x
andy
must be valid for both reads and writes. - Both
x
andy
must point to initialized instances of typeT1
andT2
, respectively.
Examples
use bitvec::prelude::*;
let mut data = 2u8;
let x = BitPtr::<_, Lsb0, _>::from_mut(&mut data);
let y = unsafe { x.add(1) };
unsafe {
bitvec::ptr::swap(x, y);
}
assert_eq!(data, 1);