From 7393301a1e00346feed2ef97b675f2dc1dce04f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9A=AB=EF=B8=8F?= Date: Sun, 24 Nov 2024 22:57:55 +0100 Subject: [PATCH] fix impls for non-zerocopy case --- src/owners.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/owners.rs b/src/owners.rs index 3d8ae3d..8f0cdc7 100644 --- a/src/owners.rs +++ b/src/owners.rs @@ -31,9 +31,15 @@ where #[cfg(not(feature = "zerocopy"))] unsafe impl ByteSource for &'static [u8] { + type Owner = Self; + fn as_bytes(&self) -> &[u8] { *self } + + fn as_owner(self) -> Self::Owner { + self + } } #[cfg(feature = "zerocopy")] @@ -55,9 +61,15 @@ where #[cfg(not(feature = "zerocopy"))] unsafe impl ByteSource for Box<[u8]> { + type Owner = Self; + fn as_bytes(&self) -> &[u8] { self.as_ref() } + + fn as_owner(self) -> Self::Owner { + self + } } #[cfg(feature = "zerocopy")] @@ -79,9 +91,15 @@ where #[cfg(not(feature = "zerocopy"))] unsafe impl ByteSource for Vec { + type Owner = Self; + fn as_bytes(&self) -> &[u8] { self.as_ref() } + + fn as_owner(self) -> Self::Owner { + todo!() + } } unsafe impl ByteSource for String {