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

# Function std::ptr::read_unaligned [−] [src]

    pub unsafe fn read_unaligned<T>(src: *const T) -> T

🔬 This is a nightly-only experimental API. (`ptr_unaligned` #37955)

Reads the value from `src` without moving it. This leaves the memory in `src` unchanged.

Unlike `read`, the pointer may be unaligned.

# Safety

Beyond accepting a raw pointer, this is unsafe because it semantically moves the value out of `src` without preventing further usage of `src`. If `T` is not `Copy`, then care must be taken to ensure that the value at `src` is not used before the data is overwritten again (e.g. with `write`, `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use because it will attempt to drop the value previously at `*src`.

# Examples

Basic usage:

    #![feature(ptr_unaligned)]

    let x = 12;
    let y = &x as *const i32;

    unsafe {
        assert_eq!(std::ptr::read_unaligned(y), 12);
    }Run

# 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
+
  Collapse/expand all sections

## 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`)