From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/bytemuck/src/zeroable_in_option.rs | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 vendor/bytemuck/src/zeroable_in_option.rs (limited to 'vendor/bytemuck/src/zeroable_in_option.rs') diff --git a/vendor/bytemuck/src/zeroable_in_option.rs b/vendor/bytemuck/src/zeroable_in_option.rs new file mode 100644 index 0000000..c4cf158 --- /dev/null +++ b/vendor/bytemuck/src/zeroable_in_option.rs @@ -0,0 +1,35 @@ +use super::*; + +// Note(Lokathor): This is the neat part!! +unsafe impl Zeroable for Option {} + +/// Trait for types which are [Zeroable](Zeroable) when wrapped in +/// [Option](core::option::Option). +/// +/// ## Safety +/// +/// * `Option` must uphold the same invariants as +/// [Zeroable](Zeroable). +pub unsafe trait ZeroableInOption: Sized {} + +unsafe impl ZeroableInOption for NonZeroI8 {} +unsafe impl ZeroableInOption for NonZeroI16 {} +unsafe impl ZeroableInOption for NonZeroI32 {} +unsafe impl ZeroableInOption for NonZeroI64 {} +unsafe impl ZeroableInOption for NonZeroI128 {} +unsafe impl ZeroableInOption for NonZeroIsize {} +unsafe impl ZeroableInOption for NonZeroU8 {} +unsafe impl ZeroableInOption for NonZeroU16 {} +unsafe impl ZeroableInOption for NonZeroU32 {} +unsafe impl ZeroableInOption for NonZeroU64 {} +unsafe impl ZeroableInOption for NonZeroU128 {} +unsafe impl ZeroableInOption for NonZeroUsize {} + +// Note: this does not create NULL vtable because we get `None` anyway. +unsafe impl ZeroableInOption for NonNull {} +unsafe impl ZeroableInOption for &'_ T {} +unsafe impl ZeroableInOption for &'_ mut T {} + +#[cfg(feature = "extern_crate_alloc")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "extern_crate_alloc")))] +unsafe impl ZeroableInOption for alloc::boxed::Box {} -- cgit v1.2.3