pub unsafe fn copy<O1, O2, T1, T2>(
src: BitPtr<Const, O1, T1>,
dst: BitPtr<Mut, O2, T2>,
count: usize
) where
O1: BitOrder,
O2: BitOrder,
T1: BitStore,
T2: BitStore,
Expand description
Copies count
bits from src
to dst
. The source and destination may
overlap.
If the source and destination will never overlap, copy_nonoverlapping
can be used instead.
copy
is semantically equivalent to C’s memmove
, but with the argument
order swapped. Copying takes place as if the bits were copied from src
to
a temporary array, then copied from the array into dst
.
Original
API Differences
The pointers may differ in bit-ordering or storage element types. bitvec
considers it Undefined Behavior for two pointer regions to overlap in memory
if they have different bit-orderings, and so will only perform overlap
detection when O1
and O2
match.
Safety
Behavior is undefined if any of the following conditions are violated:
src
must be valid for reads ofcount
bits.dst
must be valid for writes ofcount
bits.src
anddst
must not overlap if they have different bit-ordering parameters.
The type parameters T1
and T2
are permitted to differ.
Examples
Basic usage:
use bitvec::prelude::*;
let start = 0b1011u8;
let mut end = 0u16;
unsafe {
bitvec::ptr::copy::<Lsb0, Msb0, _, _>(
(&start).into(),
(&mut end).into(),
4,
);
}
assert_eq!(end, 0b1101_0000__0000_0000);
Overlapping regions:
use bitvec::prelude::*;
let mut x = 0b1111_0010u8;
let src = BitPtr::<_, Lsb0, _>::from_mut(&mut x);
let dst = unsafe { src.add(2) };
unsafe {
bitvec::ptr::copy(src.immut(), dst, 4);
}
assert_eq!(x, 0b1100_1010);
// ^^ ^^ bottom nibble moved here