core::ptr::slice_from_raw_parts - Rust
Description: API documentation for the Rust `slice_from_raw_parts` fn in crate `core`.
Keywords: rust, rustlang, rust-lang, slice_from_raw_parts

# 1.42.0[−][src]Function core::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.

# Examples

    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);

Run