1.0.0[][src]Function sgx_tstd::slice::from_raw_parts

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

Forms a slice from a pointer and a length.

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


Behavior is undefined if any of the following conditions are violated:


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.


use std::slice;

// manifest a slice for a single element
let x = 42;
let ptr = &x as *const _;
let slice = unsafe { slice::from_raw_parts(ptr, 1) };
assert_eq!(slice[0], 42);