Skip to main content

Zeroable

Trait Zeroable 

pub unsafe trait Zeroable: Sized {
    // Provided method
    fn zeroed() -> Self { ... }
}
Available on crate features io and ancillary and bytemuck only.
Expand description

Trait for types that can be safely created with zeroed.

An all-zeroes value may or may not be the same value as the Default value of the type.

§Safety

  • Your type must be inhabited (eg: no Infallible).
  • Your type must be allowed to be an “all zeroes” bit pattern (eg: no NonNull<T>).

§Features

Some impls are feature gated due to the MSRV policy:

  • MaybeUninit<T> was not available in 1.34.0, but is available under the zeroable_maybe_uninit feature flag.
  • Atomic* types require Rust 1.60.0 or later to work on certain platforms, but is available under the zeroable_atomics feature flag.
  • [T; N] for arbitrary N requires the min_const_generics feature flag.

Provided Methods§

fn zeroed() -> Self

Calls zeroed.

This is a trait method so that you can write MyType::zeroed() in your code. It is a contract of this trait that if you implement it on your type you must not override this method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl Zeroable for bool

§

impl Zeroable for char

§

impl Zeroable for f32

§

impl Zeroable for f64

§

impl Zeroable for i8

§

impl Zeroable for i16

§

impl Zeroable for i32

§

impl Zeroable for i64

§

impl Zeroable for i128

§

impl Zeroable for isize

§

impl Zeroable for *const str

§

impl Zeroable for *mut str

§

impl Zeroable for u8

§

impl Zeroable for u16

§

impl Zeroable for u32

§

impl Zeroable for u64

§

impl Zeroable for u128

§

impl Zeroable for ()

§

impl Zeroable for usize

§

impl Zeroable for __m128

Available on x86-64 only.
§

impl Zeroable for __m128d

Available on x86-64 only.
§

impl Zeroable for __m128i

Available on x86-64 only.
§

impl Zeroable for __m256

Available on x86-64 only.
§

impl Zeroable for __m256d

Available on x86-64 only.
§

impl Zeroable for __m256i

Available on x86-64 only.
§

impl Zeroable for PhantomPinned

§

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

§

impl<A, B> Zeroable for (A, B)
where A: Zeroable, B: Zeroable,

§

impl<A, B, C> Zeroable for (A, B, C)
where A: Zeroable, B: Zeroable, C: Zeroable,

§

impl<A, B, C, D> Zeroable for (A, B, C, D)
where A: Zeroable, B: Zeroable, C: Zeroable, D: Zeroable,

§

impl<A, B, C, D, E> Zeroable for (A, B, C, D, E)
where A: Zeroable, B: Zeroable, C: Zeroable, D: Zeroable, E: Zeroable,

§

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

§

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

§

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

§

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

§

impl<T> Zeroable for *const [T]

§

impl<T> Zeroable for *const T

§

impl<T> Zeroable for *mut [T]

§

impl<T> Zeroable for *mut T

§

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

§

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

§

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

§

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

§

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

§

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

§

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

Available on crate feature min_const_generics only.

Implementors§