Function bitvec::slice::from_raw_parts_mut
source · [−]pub unsafe fn from_raw_parts_mut<'a, O, T>(
data: BitPtr<Mut, O, T>,
len: usize
) -> Result<&'a mut BitSlice<O, T>, BitSpanError<T>> where
O: BitOrder,
T: BitStore,
Expand description
Performs the same functionality as from_raw_parts
, except that a mutable
slice is returned.
Original
API Differences
This takes a BitPtr
as its base address, rather than a raw *Bit
pointer, as bitvec
does not provide raw pointers to individual bits.
It returns a Result
, because the len
argument may be invalid to encode
into a &BitSlice
reference.
Safety
Behavior is undefined if any of the following conditions are violated:
data
must be valid for boths reads and writes forlen
many bits, and it must be properly aligned. This means in particular:- The entire memory range of this slice must be contained within a single allocated object! Slices can never span across multiple allocated objects.
data
must be non-null, and itsT
portion must be aligned. Both of these conditions are checked during safe construction of theBitPtr
, andunsafe
construction of it must not violate them. Doing so will cause incorrect behavior in the crate.
data
must point tolen
consecutive bits within properly initialized memory elementsT
.- The memory referenced by the returned slice must not be accessed through
any other pointer (not derived from the return value) for the duration of
lifetime
'a
. Both read and write accesses are forbidden. This is true even ifT
supports aliased mutation! An&mut
reference requires exclusive access for its lifetime. len
cannot exceedBitSlice::MAX_BITS
.