Function core::slice::from_raw_bufDeprecated [-] [+] [src]

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

Forms a slice from a pointer and a length.

The pointer given is actually a reference to the base of the slice. This reference is used to give a concrete lifetime to tie the returned slice to. Typically this should indicate that the slice is valid for as long as the pointer itself is valid.

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

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

Example

fn main() { use std::slice; // manifest a slice out of thin air! let ptr = 0x1234 as *const usize; let amt = 10; unsafe { let slice = slice::from_raw_buf(&ptr, amt); } }
use std::slice;

// manifest a slice out of thin air!
let ptr = 0x1234 as *const usize;
let amt = 10;
unsafe {
    let slice = slice::from_raw_buf(&ptr, amt);
}