From 78f8ad9e356b49c5de5363a607a5b1d0b3b30287 Mon Sep 17 00:00:00 2001 From: Rick Richardson Date: Mon, 14 Nov 2022 16:28:58 -0800 Subject: [PATCH 1/2] add CheckBytes impl for mem::ManuallyDrop --- bytecheck/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bytecheck/src/lib.rs b/bytecheck/src/lib.rs index b1f2107..694ba84 100644 --- a/bytecheck/src/lib.rs +++ b/bytecheck/src/lib.rs @@ -153,6 +153,7 @@ use core::{ convert::{Infallible, TryFrom}, fmt, marker::{PhantomData, PhantomPinned}, + mem::ManuallyDrop, num::{ NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, @@ -283,6 +284,16 @@ impl CheckBytes for PhantomPinned { } } +impl> CheckBytes for ManuallyDrop { + type Error = T::Error; + + #[inline] + unsafe fn check_bytes<'a>(value: *const Self, c: &mut C) -> Result<&'a Self, Self::Error> { + let _ = T::check_bytes(value as *const T, c)?; + Ok(&*value) + } +} + /// An error resulting from an invalid boolean. /// /// Booleans are one byte and may only have the value 0 or 1. From 367cf10b6591981d45d1abf6e8cc1fbc15543a63 Mon Sep 17 00:00:00 2001 From: Rick Richardson Date: Mon, 14 Nov 2022 16:48:39 -0800 Subject: [PATCH 2/2] plus ?sized --- bytecheck/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bytecheck/src/lib.rs b/bytecheck/src/lib.rs index 694ba84..fdfcfba 100644 --- a/bytecheck/src/lib.rs +++ b/bytecheck/src/lib.rs @@ -284,7 +284,7 @@ impl CheckBytes for PhantomPinned { } } -impl> CheckBytes for ManuallyDrop { +impl + ?Sized> CheckBytes for ManuallyDrop { type Error = T::Error; #[inline]