Text of rust.docs.kernel.org › next › pin_init › trait.Zeroable.html as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

Zeroable in pin_init - Rust

Skip to main content Zeroable pin_init 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() . As const traits are not yet stable, pin_init::zeroed() can be used instead when initialization is required in a const context. § Examples use pin_init::Zeroable; #[derive(Zeroable)] struct Point { x: u32, y: u32, } let point: Point = Zeroable::zeroed(); assert_eq! (point.x, 0 ); assert_eq! (point.y, 0 ); Dyn Compatibility § This trait is dyn compatible .

In older versions of Rust, dyn compatibility was called "object safety". Implementations on Foreign Types § Source § impl Zeroable for () Source § impl Zeroable for *const str Source § impl Zeroable for *mut str Source § impl Zeroable for PhantomPinned 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 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 usize Source § impl<J: Zeroable > Zeroable for (J₁, J₂, …, Jₙ) Implemented for tuples up to 10 items long.

Source § impl<T: ? Sized + Zeroable > Zeroable for UnsafeCell <T> Source § impl<T: ? Sized > Zeroable for PhantomData <T> Source § impl<T: Zeroable > Zeroable for Wrapping <T> Source § impl<T: ZeroableOption > Zeroable for Option <T> 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 MaybeUninit <T> Source § impl<const N: usize , T: Zeroable > Zeroable for [T; N] Implementors §