pub unsafe fn zeroed<T>() -> T
Creates a value whose bytes are all zero.
This has the same effect as MaybeUninit::zeroed().assume_init()
. 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
. 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.
Correct usage of this function: initializing an integer with zero.
Incorrect usage of this function: initializing a reference with zero.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/mem/fn.zeroed.html