This exchanges the bit-values in two locations. It is semantically and behaviorally equivalent to BitRef::swap
, except that it works on bit-pointer structures rather than proxy references. Prefer to use a proxy reference or BitSlice::swap
instead.
This has the same safety requirements as ptr::read
and ptr::write
, as it is required to use them in its implementation.
use bitvec::prelude::*; use bitvec::ptr as bv_ptr; let mut data = 2u8; let x = BitPtr::<_, _, Lsb0>::from_mut(&mut data); let y = unsafe { x.add(1) }; unsafe { bv_ptr::swap(x, y); } assert_eq!(data, 1);