1.42.0[][src]Function sgx_tstd::ptr::slice_from_raw_parts

pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T]

Forms a raw slice from a pointer and a length.

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

This function is safe, but actually using the return value is unsafe. See the documentation of from_raw_parts for slice safety requirements.


use std::ptr;

// create a slice pointer when starting out with a pointer to the first element
let x = [5, 6, 7];
let ptr = x.as_ptr();
let slice = ptr::slice_from_raw_parts(ptr, 3);
assert_eq!(unsafe { &*slice }[2], 7);