From 1728b9b2c432741203d47207254c9f89fa32883b Mon Sep 17 00:00:00 2001 From: p6nj Date: Fri, 17 Jan 2025 19:15:33 -0500 Subject: [PATCH] rename apply to map just like the image crate, one more test --- bingus/src/img/image.rs | 17 ++++++++++++++++- bingus/src/lib.rs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bingus/src/img/image.rs b/bingus/src/img/image.rs index bfcbe95..bf0ff66 100644 --- a/bingus/src/img/image.rs +++ b/bingus/src/img/image.rs @@ -65,7 +65,7 @@ where P: Send + Sync, { type Unit = P; - fn apply Self::Unit + Sync>(mut self, f: F) -> Self { + fn map Self::Unit + Sync>(mut self, f: F) -> Self { self.par_pixels_mut().for_each(|p| *p = f(p)); self } @@ -186,4 +186,19 @@ mod tests { ) } } + + #[cfg(test)] + mod effects { + use crate::Bendable; + + use super::super::{Pixel, RgbImage}; + + #[test] + fn fill_with_funny_number() { + let image = RgbImage::new(8, 16); + let new_image = image.clone().map(|p| p.map(|_channel| 42u8)); + assert_ne!(image.clone(), new_image); + assert_eq!(42, new_image.get_pixel(1, 2).channels()[1]) + } + } } diff --git a/bingus/src/lib.rs b/bingus/src/lib.rs index 238b5b8..a463ffa 100644 --- a/bingus/src/lib.rs +++ b/bingus/src/lib.rs @@ -18,7 +18,7 @@ pub trait Bendable: TryFromDataBytes + IntoDataBytes { ) -> Result::Error> { Self::try_from_bytes(b.into_bytes(), format) } - fn apply Self::Unit + Sync>(self, f: F) -> Self; + fn map Self::Unit + Sync>(self, f: F) -> Self; } pub trait IntoDataBytes: Sized {