RawData, clippy

This commit is contained in:
Ponj 2024-07-13 09:07:50 +02:00
parent 5d39e227b6
commit e34287df9e
Signed by: p6nj
GPG key ID: CEAB625B75A836B2
4 changed files with 56 additions and 3 deletions

View file

@ -18,3 +18,6 @@ dasp_sample = "0.11.0"
rayon = "1.10.0"
dirs = "5.0.1"
rfd = "0.14.1"
derive-new = "0.6.0"
infer = "0.16.0"
indicatif = { version = "0.17.8", features = ["rayon"] }

View file

@ -19,5 +19,6 @@ dasp_sample = { workspace = true }
rayon = { workspace = true }
dirs = { workspace = true }
rfd = { workspace = true }
derive-new = "0.6.0"
indicatif = { version = "0.17.8", features = ["rayon"] }
derive-new = { workspace = true }
infer = { workspace = true }
indicatif = { workspace = true }

View file

@ -81,7 +81,7 @@ fn main() -> Result<()> {
"[{eta}] {bar:40.green/red} {pos}/{len} pixels",
)?)
.map(|px: &[u8]| (px[2] as i32) | ((px[1] as i32) << 8) | ((px[0] as i32) << 16))
.map(|px| U24::new_unchecked(px))
.map(U24::new_unchecked)
.map(|x| uparc(x.to_sample()))
.flat_map(|sample: f32| {
let rgb: U24 = sample.to_sample();

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(),
}
}
}