Function bitvec::slice::from_raw_parts[][src]

pub unsafe fn from_raw_parts<'a, O, T>(
    data: *const T,
    len: usize
) -> &'a BitSlice<O, T> where
    O: BitOrder,
    T: 'a + BitStore

Forms a bit slice from a pointer and a length.

The len argument is the number of elements, not the number of bits.

Safety

This function is unsafe as there is no guarantee that the given pointer is valid for len elements, nor whether the lifetime inferred is a suitable lifetime for the returned slice.

data must be non-null and aligned, even for zero-length slices. This is due to requirements in the bitvec data structure operations. You can obtain a pointer that is usable as data for zero-length slices from NonNull::dangling().

The total size of the bit slice must be no larger than BitPtr::<T>::MAX_BITS bits in memory. See the safety documentation of BitPtr (if available).

Caveat

The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse, it’s suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the slice, or by explicit annotation.

Original

core::slice::from_raw_parts

Examples

use bitvec::slice as bitslice;

//  manifest a slice for a single element
let x = 42u8; // 0b0010_1010
let ptr = &x as *const _;
let bitslice = unsafe { bitslice::from_raw_parts::<Msb0, _>(ptr, 1) };
assert!(bitslice[2]);