1use super::*;
2
3// Note(Lokathor): This is the neat part!!
4unsafe impl<T: ZeroableInOption> Zeroable for Option<T> {}
5
6/// Trait for types which are [Zeroable](Zeroable) when wrapped in
7/// [Option](core::option::Option).
8///
9/// ## Safety
10///
11/// * `Option<YourType>` must uphold the same invariants as
12/// [Zeroable](Zeroable).
13pub unsafe trait ZeroableInOption: Sized {}
14
15unsafe impl ZeroableInOption for NonZeroI8 {}
16unsafe impl ZeroableInOption for NonZeroI16 {}
17unsafe impl ZeroableInOption for NonZeroI32 {}
18unsafe impl ZeroableInOption for NonZeroI64 {}
19unsafe impl ZeroableInOption for NonZeroI128 {}
20unsafe impl ZeroableInOption for NonZeroIsize {}
21unsafe impl ZeroableInOption for NonZeroU8 {}
22unsafe impl ZeroableInOption for NonZeroU16 {}
23unsafe impl ZeroableInOption for NonZeroU32 {}
24unsafe impl ZeroableInOption for NonZeroU64 {}
25unsafe impl ZeroableInOption for NonZeroU128 {}
26unsafe impl ZeroableInOption for NonZeroUsize {}
27
28// Note: this does not create NULL vtable because we get `None` anyway.
29unsafe impl<T: ?Sized> ZeroableInOption for NonNull<T> {}
30unsafe impl<T: ?Sized> ZeroableInOption for &'_ T {}
31unsafe impl<T: ?Sized> ZeroableInOption for &'_ mut T {}
32
33#[cfg(feature = "extern_crate_alloc")]
34#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "extern_crate_alloc")))]
35unsafe impl<T: ?Sized> ZeroableInOption for alloc::boxed::Box<T> {}
36