pub unsafe trait Zeroable {
// Provided methods
fn init_zeroed() -> impl Init<Self>
where Self: Sized { ... }
fn zeroed() -> Self
where Self: Sized { ... }
}
Expand description
Provided Methods§
Sourcefn init_zeroed() -> impl Init<Self>where
Self: Sized,
fn init_zeroed() -> impl Init<Self>where
Self: Sized,
Create a new zeroed Self
.
The returned initializer will write 0x00
to every byte of the given slot
.
Sourcefn zeroed() -> Selfwhere
Self: Sized,
fn zeroed() -> Selfwhere
Self: Sized,
Create a Self
consisting of all zeroes.
Whenever a type implements Zeroable
, this function should be preferred over
core::mem::zeroed()
or using MaybeUninit<T>::zeroed().assume_init()
.
§Examples
use pin_init::{Zeroable, zeroed};
#[derive(Zeroable)]
struct Point {
x: u32,
y: u32,
}
let point: Point = zeroed();
assert_eq!(point.x, 0);
assert_eq!(point.y, 0);