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

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

Returns the value of type `T` represented by the all-zero byte-pattern.

This means that, for example, the padding byte in `(u8, u16)` is not necessarily zeroed.

There is no guarantee that an all-zero byte-pattern represents a valid value of some type `T`. For example, the all-zero byte-pattern is not a valid value for reference types (`&T` and `&mut T`). Using `zeroed` on such types causes immediate undefined behavior because the Rust compiler assumes that there always is a valid value in a variable it considers initialized.

This has the same effect as `MaybeUninit::zeroed().assume_init()`. It is useful for FFI sometimes, but should generally be avoided.

# Examples

Correct usage of this function: initializing an integer with zero.

    use std::mem;

    let x: i32 = unsafe { mem::zeroed() };
    assert_eq!(0, x);Run

Incorrect usage of this function: initializing a reference with zero.

    use std::mem;

    let _x: &i32 = unsafe { mem::zeroed() }; // Undefined behavior!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`)