From e34287df9ed570816c6c4a1f034719c7f6de6654 Mon Sep 17 00:00:00 2001 From: p6nj Date: Sat, 13 Jul 2024 09:07:50 +0200 Subject: [PATCH] RawData, clippy --- Cargo.toml | 3 +++ bent-funny-zone/Cargo.toml | 5 ++-- bent-funny-zone/src/main.rs | 2 +- bingus/src/lib.rs | 49 +++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 704f945..56117cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/bent-funny-zone/Cargo.toml b/bent-funny-zone/Cargo.toml index 6306660..1d7e5a2 100644 --- a/bent-funny-zone/Cargo.toml +++ b/bent-funny-zone/Cargo.toml @@ -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 } diff --git a/bent-funny-zone/src/main.rs b/bent-funny-zone/src/main.rs index e04dc8b..733408a 100644 --- a/bent-funny-zone/src/main.rs +++ b/bent-funny-zone/src/main.rs @@ -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(); diff --git a/bingus/src/lib.rs b/bingus/src/lib.rs index 8b13789..ce40a72 100644 --- a/bingus/src/lib.rs +++ b/bingus/src/lib.rs @@ -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> for Vec +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(), + } + } +}