# Function bitflags::__core::slice::from_raw_parts [−] [src]

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

1.0.0

Forms a slice from a pointer and a length.

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

# Safety

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

`p` must be non-null, even for zero-length slices.

# Caveat

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.

# Examples

    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_parts(ptr, amt);
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)