Function bitvec::ptr::swap_nonoverlapping[][src]

pub unsafe fn swap_nonoverlapping<O1, O2, T1, T2>(
    x: BitPtr<Mut, O1, T1>,
    y: BitPtr<Mut, O2, T2>,
    count: usize
) where
    O1: BitOrder,
    O2: BitOrder,
    T1: BitStore,
    T2: BitStore

Swaps count bits between the two regions of memory beginning at x and y. The two regions must not overlap.

Original

ptr::swap_nonoverlapping

Safety

Behavior is undefined if any of the following conditions are violated:

  • Both x and y must be valid for both reads and writes of count bits.
  • Both x and y must be fully initialized instances of T for all count bits.
  • The regions may have overlapping elements, but must not overlap the concrete bits they describe.

Note that even if count is 0, the pointers must still be validly constructed, non-null, and well-aligned.

Examples

use bitvec::prelude::*;

let mut x = [0u8; 2];
let mut y = !0u16;
let x_ptr = BitPtr::<_, Lsb0, _>::from_mut(&mut x[0]);
let y_ptr = BitPtr::<_, Msb0, _>::from_mut(&mut y);

unsafe {
  bitvec::ptr::swap_nonoverlapping(x_ptr, y_ptr, 16);
}
assert_eq!(x, [!0; 2]);
assert_eq!(y, 0);