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

# 1.0.0[−][src]Function std::mem::zeroed

    pub unsafe fn zeroed<T>() -> T

Deprecating in 2.0.0:

use `mem::MaybeUninit::zeroed` instead

Creates a value whose bytes are all zero.

This has the same effect as allocating space with `mem::uninitialized` and then zeroing it out. It is useful for FFI sometimes, but should generally be avoided.

There is no guarantee that an all-zero byte-pattern represents a valid value of some type `T`. If `T` has a destructor and the value is destroyed (due to a panic or the end of a scope) before being initialized, then the destructor will run on zeroed data, likely leading to undefined behavior.

See also the documentation for `mem::uninitialized`, which has many of the same caveats.

# Examples

    use std::mem;

    let x: i32 = unsafe { mem::zeroed() };
    assert_eq!(0, x);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`)