Skip to content

Commit

Permalink
der: impl RefToOwned/OwnedToRef for &[u8]/Box<[u8]>
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
  • Loading branch information
baloo committed Aug 7, 2023
1 parent 345b138 commit 755f23b
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 755f23b

Please sign in to comment.