mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-27 22:13:12 -08:00
feat: A variety of utilities in preparation for implementing the API
This commit is contained in:
27
util/src/zerocopy/zerocopy_ref_ext.rs
Normal file
27
util/src/zerocopy/zerocopy_ref_ext.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use zerocopy::{ByteSlice, ByteSliceMut, Ref};
|
||||
|
||||
pub trait ZerocopyEmancipateExt<B, T> {
|
||||
fn emancipate(&self) -> Ref<&[u8], T>;
|
||||
}
|
||||
|
||||
pub trait ZerocopyEmancipateMutExt<B, T> {
|
||||
fn emancipate_mut(&mut self) -> Ref<&mut [u8], T>;
|
||||
}
|
||||
|
||||
impl<B, T> ZerocopyEmancipateExt<B, T> for Ref<B, T>
|
||||
where
|
||||
B: ByteSlice,
|
||||
{
|
||||
fn emancipate(&self) -> Ref<&[u8], T> {
|
||||
Ref::new(self.bytes()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, T> ZerocopyEmancipateMutExt<B, T> for Ref<B, T>
|
||||
where
|
||||
B: ByteSliceMut,
|
||||
{
|
||||
fn emancipate_mut(&mut self) -> Ref<&mut [u8], T> {
|
||||
Ref::new(self.bytes_mut()).unwrap()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user