1 | use super::*;
|
2 |
|
3 | // Note(Lokathor): This is the neat part!!
|
4 | unsafe 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).
|
13 | pub unsafe trait ZeroableInOption: Sized {}
|
14 |
|
15 | unsafe impl ZeroableInOption for NonZeroI8 {}
|
16 | unsafe impl ZeroableInOption for NonZeroI16 {}
|
17 | unsafe impl ZeroableInOption for NonZeroI32 {}
|
18 | unsafe impl ZeroableInOption for NonZeroI64 {}
|
19 | unsafe impl ZeroableInOption for NonZeroI128 {}
|
20 | unsafe impl ZeroableInOption for NonZeroIsize {}
|
21 | unsafe impl ZeroableInOption for NonZeroU8 {}
|
22 | unsafe impl ZeroableInOption for NonZeroU16 {}
|
23 | unsafe impl ZeroableInOption for NonZeroU32 {}
|
24 | unsafe impl ZeroableInOption for NonZeroU64 {}
|
25 | unsafe impl ZeroableInOption for NonZeroU128 {}
|
26 | unsafe impl ZeroableInOption for NonZeroUsize {}
|
27 |
|
28 | // Note: this does not create NULL vtable because we get `None` anyway.
|
29 | unsafe impl<T: ?Sized> ZeroableInOption for NonNull<T> {}
|
30 | unsafe impl<T: ?Sized> ZeroableInOption for &'_ T {}
|
31 | unsafe 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" )))]
|
35 | unsafe impl<T: ?Sized> ZeroableInOption for alloc::boxed::Box<T> {}
|
36 | |