RawData, clippy

This commit is contained in:
Breval Ferrari 2024-07-13 09:07:50 +02:00
parent 5d39e227b6
commit e34287df9e
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
4 changed files with 56 additions and 3 deletions

View file

@ -1 +1,50 @@
use std::{borrow::Cow, ops::Deref};
type Bytes<'a> = Cow<'a, [u8]>;
pub trait Metadata {}
pub struct RawData<'a, M: Metadata> {
pub(crate) data: Bytes<'a>,
pub(crate) metadata: M,
}
impl<'a, M> RawData<'a, M>
where
M: Metadata,
{
fn metadata(&self) -> &M {
&self.metadata
}
}
impl<'a, M> Deref for RawData<'a, M>
where
M: Metadata,
{
type Target = Bytes<'a>;
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl<'a, M> From<RawData<'a, M>> for Vec<u8>
where
M: Metadata,
{
fn from(value: RawData<'a, M>) -> Self {
value.data.into_owned()
}
}
impl<'a, M> Clone for RawData<'a, M>
where
M: Metadata + Clone,
{
fn clone(&self) -> Self {
Self {
data: self.data.clone(),
metadata: self.metadata().clone(),
}
}
}