Skip to content

Commit

Permalink
der: impl RefToOwned/OwnedToRef for &[u8]/Box<[u8]> (#1188)
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Gautier <[email protected]>
  • Loading branch information
baloo authored Aug 7, 2023
1 parent ff3ade6 commit 00fbef3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions der/src/referenced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

0 comments on commit 00fbef3

Please sign in to comment.