Skip to main content

slice_from_raw_parts

Function slice_from_raw_parts 

Source
pub const unsafe fn slice_from_raw_parts<'a, T>(
    data: *const T,
    len: usize,
) -> &'a [T]
Expand description

Forms a slice from an FFI pointer and a length, returning an empty slice &[] when len == 0 even if data is null or misaligned.

ยงSafety

If len > 0, data must satisfy the safety requirements of [core::slice::from_raw_parts]: it must be non-null, valid for reads for len * mem::size_of::<T>() many bytes, properly aligned, and point to len consecutive properly initialized values of type T that are not mutated for the duration of lifetime 'a.