Function bitvec::ptr::swap

source ·
pub unsafe fn swap<T1, T2, O1, O2>(
    one: BitPtr<Mut, T1, O1>,
    two: BitPtr<Mut, T2, O2>
)where
    T1: BitStore,
    T2: BitStore,
    O1: BitOrder,
    O2: BitOrder,
Expand description

Bit Swap

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.

Original

ptr::swap

Safety

This has the same safety requirements as ptr::read and ptr::write, as it is required to use them in its implementation.

Examples

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);