From 755f23bf0a01c09ac01566eda12e7e61e54bde69 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Fri, 4 Aug 2023 19:08:21 +0000 Subject: [PATCH] der: impl `RefToOwned`/`OwnedToRef` for `&[u8]`/`Box<[u8]>` Signed-off-by: Arthur Gautier --- der/src/referenced.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/der/src/referenced.rs b/der/src/referenced.rs index bb920db3a..b0c8f0325 100644 --- a/der/src/referenced.rs +++ b/der/src/referenced.rs @@ -45,3 +45,25 @@ where self.as_ref().map(|o| o.ref_to_owned()) } } + +#[cfg(feature = "alloc")] +mod allocating { + use super::{OwnedToRef, RefToOwned}; + use alloc::boxed::Box; + + impl<'a> RefToOwned<'a> for &'a [u8] { + type Owned = Box<[u8]>; + + fn ref_to_owned(&self) -> Self::Owned { + Box::from(*self) + } + } + + impl OwnedToRef for Box<[u8]> { + type Borrowed<'a> = &'a [u8]; + + fn owned_to_ref(&self) -> Self::Borrowed<'_> { + self.as_ref() + } + } +}