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

# 1.0.0[−][src]Function std::ptr::write

    pub unsafe fn write<T>(dst: *mut T, src: T)

Overwrites a memory location with the given value without reading or dropping the old value.

# Safety

This operation is marked unsafe because it accepts a raw pointer.

It does not drop the contents of `dst`. This is safe, but it could leak allocations or resources, so care must be taken not to overwrite an object that should be dropped.

Additionally, it does not drop `src`. Semantically, `src` is moved into the location pointed to by `dst`.

This is appropriate for initializing uninitialized memory, or overwriting memory that has previously been `read` from.

The pointer must be aligned; use `write_unaligned` if that is not the case.

# Examples

Basic usage:

    let mut x = 0;
    let y = &mut x as *mut i32;
    let z = 12;

    unsafe {
        std::ptr::write(y, z);
        assert_eq!(std::ptr::read(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
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse 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`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)