Trait Zeroable

Source
pub unsafe trait Zeroable {
    // Provided methods
    fn init_zeroed() -> impl Init<Self>
       where Self: Sized { ... }
    fn zeroed() -> Self
       where Self: Sized { ... }
}
Expand description

Marker trait for types that can be initialized by writing just zeroes.

§Safety

The bit pattern consisting of only zeroes is a valid bit pattern for this type. In other words, this is not UB:

let val: Self = unsafe { core::mem::zeroed() };

Provided Methods§

Source

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.

Source

fn zeroed() -> Self
where 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);

Implementations on Foreign Types§

Source§

impl Zeroable for Option<NonZero<i8>>

Source§

impl Zeroable for Option<NonZero<i16>>

Source§

impl Zeroable for Option<NonZero<i32>>

Source§

impl Zeroable for Option<NonZero<i64>>

Source§

impl Zeroable for Option<NonZero<i128>>

Source§

impl Zeroable for Option<NonZero<isize>>

Source§

impl Zeroable for Option<NonZero<u8>>

Source§

impl Zeroable for Option<NonZero<u16>>

Source§

impl Zeroable for Option<NonZero<u32>>

Source§

impl Zeroable for Option<NonZero<u64>>

Source§

impl Zeroable for Option<NonZero<u128>>

Source§

impl Zeroable for Option<NonZero<usize>>

Source§

impl Zeroable for bool

Source§

impl Zeroable for char

Source§

impl Zeroable for f32

Source§

impl Zeroable for f64

Source§

impl Zeroable for i8

Source§

impl Zeroable for i16

Source§

impl Zeroable for i32

Source§

impl Zeroable for i64

Source§

impl Zeroable for i128

Source§

impl Zeroable for isize

Source§

impl Zeroable for *const str

Source§

impl Zeroable for *mut str

Source§

impl Zeroable for u8

Source§

impl Zeroable for u16

Source§

impl Zeroable for u32

Source§

impl Zeroable for u64

Source§

impl Zeroable for u128

Source§

impl Zeroable for ()

Source§

impl Zeroable for usize

Source§

impl Zeroable for PhantomPinned

Source§

impl<A, B, C, D, E, F, G, H, I, J> Zeroable for (A, B, C, D, E, F, G, H, I, J)
where A: Zeroable, B: Zeroable, C: Zeroable, D: Zeroable, E: Zeroable, F: Zeroable, G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<B, C, D, E, F, G, H, I, J> Zeroable for (B, C, D, E, F, G, H, I, J)
where B: Zeroable, C: Zeroable, D: Zeroable, E: Zeroable, F: Zeroable, G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<C, D, E, F, G, H, I, J> Zeroable for (C, D, E, F, G, H, I, J)
where C: Zeroable, D: Zeroable, E: Zeroable, F: Zeroable, G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<D, E, F, G, H, I, J> Zeroable for (D, E, F, G, H, I, J)
where D: Zeroable, E: Zeroable, F: Zeroable, G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<E, F, G, H, I, J> Zeroable for (E, F, G, H, I, J)
where E: Zeroable, F: Zeroable, G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<F, G, H, I, J> Zeroable for (F, G, H, I, J)
where F: Zeroable, G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<G, H, I, J> Zeroable for (G, H, I, J)
where G: Zeroable, H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<H, I, J> Zeroable for (H, I, J)
where H: Zeroable, I: Zeroable, J: Zeroable,

Source§

impl<I, J> Zeroable for (I, J)
where I: Zeroable, J: Zeroable,

Source§

impl<J> Zeroable for (J,)
where J: Zeroable,

Source§

impl<T> Zeroable for Option<T>
where T: ZeroableOption,

Source§

impl<T> Zeroable for *const [T]

Source§

impl<T> Zeroable for *const T

Source§

impl<T> Zeroable for *mut [T]

Source§

impl<T> Zeroable for *mut T

Source§

impl<T> Zeroable for UnsafeCell<T>
where T: Zeroable + ?Sized,

Source§

impl<T> Zeroable for PhantomData<T>
where T: ?Sized,

Source§

impl<T> Zeroable for Wrapping<T>
where T: Zeroable,

Source§

impl<T> Zeroable for MaybeUninit<T>

Source§

impl<const N: usize, T> Zeroable for [T; N]
where T: Zeroable,

Implementors§

Source§

impl<T> Zeroable for Opaque<T>