From b7ba2c3637f2c49a582017d0127c690eff5a6631 Mon Sep 17 00:00:00 2001 From: Elbert Ronnie <103196773+elbertronnie@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:53:22 +0530 Subject: [PATCH] Raw-rs: Remove fortuples dependency (#2082) Remove fortuples from Raw-rs --- libraries/raw-rs/Cargo.lock | 49 ++++++---------------- libraries/raw-rs/Cargo.toml | 1 - libraries/raw-rs/src/processing.rs | 67 +++++++++++++++++++----------- 3 files changed, 55 insertions(+), 62 deletions(-) diff --git a/libraries/raw-rs/Cargo.lock b/libraries/raw-rs/Cargo.lock index 60ed8a30c9..d9ec4482c8 100644 --- a/libraries/raw-rs/Cargo.lock +++ b/libraries/raw-rs/Cargo.lock @@ -49,7 +49,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -144,7 +144,7 @@ version = "0.0.1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", "toml", ] @@ -384,17 +384,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fortuples" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87630a8087e9cac4b7edfb6ee5e250ddca9112b57b6b17d8f5107375a3a8eace" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "futures-channel" version = "0.3.31" @@ -698,7 +687,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -934,7 +923,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -984,7 +973,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -1025,7 +1014,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -1132,7 +1121,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30" dependencies = [ "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -1244,7 +1233,6 @@ version = "0.0.1" dependencies = [ "bitstream-io", "build-camera-data", - "fortuples", "image", "libraw-rs", "num_enum", @@ -1458,7 +1446,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -1555,17 +1543,6 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.79" @@ -1625,7 +1602,7 @@ name = "tag-derive" version = "0.0.1" dependencies = [ "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -1664,7 +1641,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -1905,7 +1882,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn", "wasm-bindgen-shared", ] @@ -1939,7 +1916,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2105,7 +2082,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] diff --git a/libraries/raw-rs/Cargo.toml b/libraries/raw-rs/Cargo.toml index 0c380697b8..51cec7b6c5 100644 --- a/libraries/raw-rs/Cargo.toml +++ b/libraries/raw-rs/Cargo.toml @@ -31,7 +31,6 @@ build-camera-data = { path = "build-camera-data" } # Required dependencies bitstream-io = "2.5.3" num_enum = "0.7.3" -fortuples = "0.9.1" thiserror = "1.0.64" # Optional dependencies (should be dev dependencies, but Cargo currently doesn't allow optional dev dependencies) diff --git a/libraries/raw-rs/src/processing.rs b/libraries/raw-rs/src/processing.rs index 6ba4dba54d..27fab471fc 100644 --- a/libraries/raw-rs/src/processing.rs +++ b/libraries/raw-rs/src/processing.rs @@ -1,5 +1,4 @@ use crate::CHANNELS_IN_RGB; -use fortuples::fortuples; #[derive(Clone, Copy)] pub struct RawPixel { @@ -25,21 +24,30 @@ impl u16> RawPixelTransform for T { } } -fortuples! { - #[tuples::min_size(1)] - #[tuples::max_size(8)] - impl RawPixelTransform for #Tuple - where - #(#Member: RawPixelTransform),* - { - fn apply(&mut self, mut pixel: RawPixel) -> u16 { - #(pixel.value = #self.apply(pixel);)* +macro_rules! impl_raw_pixel_transform { + ($($idx:tt $t:tt),+) => { + impl<$($t,)+> RawPixelTransform for ($($t,)+) + where + $($t: RawPixelTransform,)+ + { + fn apply(&mut self, mut pixel: RawPixel) -> u16 { + $(pixel.value = self.$idx.apply(pixel);)* - pixel.value - } - } + pixel.value + } + } + }; } +impl_raw_pixel_transform!(0 A); +impl_raw_pixel_transform!(0 A, 1 B); +impl_raw_pixel_transform!(0 A, 1 B, 2 C); +impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D); +impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E); +impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F); +impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G); +impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H); + pub trait PixelTransform { fn apply(&mut self, pixel: Pixel) -> [u16; CHANNELS_IN_RGB]; } @@ -50,17 +58,26 @@ impl [u16; CHANNELS_IN_RGB]> PixelTransform for T { } } -fortuples! { - #[tuples::min_size(1)] - #[tuples::max_size(8)] - impl PixelTransform for #Tuple - where - #(#Member: PixelTransform),* - { - fn apply(&mut self, mut pixel: Pixel) -> [u16; CHANNELS_IN_RGB] { - #(pixel.values = #self.apply(pixel);)* +macro_rules! impl_pixel_transform { + ($($idx:tt $t:tt),+) => { + impl<$($t,)+> PixelTransform for ($($t,)+) + where + $($t: PixelTransform,)+ + { + fn apply(&mut self, mut pixel: Pixel) -> [u16; CHANNELS_IN_RGB] { + $(pixel.values = self.$idx.apply(pixel);)* - pixel.values - } - } + pixel.values + } + } + }; } + +impl_pixel_transform!(0 A); +impl_pixel_transform!(0 A, 1 B); +impl_pixel_transform!(0 A, 1 B, 2 C); +impl_pixel_transform!(0 A, 1 B, 2 C, 3 D); +impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E); +impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F); +impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G); +impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H);