rename apply to map just like the image crate, one more test

This commit is contained in:
Breval Ferrari 2025-01-17 19:15:33 -05:00
parent 1508a03717
commit 1728b9b2c4
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
2 changed files with 17 additions and 2 deletions

View file

@ -65,7 +65,7 @@ where
P: Send + Sync, P: Send + Sync,
{ {
type Unit = P; type Unit = P;
fn apply<F: Fn(&Self::Unit) -> Self::Unit + Sync>(mut self, f: F) -> Self { fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(mut self, f: F) -> Self {
self.par_pixels_mut().for_each(|p| *p = f(p)); self.par_pixels_mut().for_each(|p| *p = f(p));
self 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])
}
}
} }

View file

@ -18,7 +18,7 @@ pub trait Bendable: TryFromDataBytes + IntoDataBytes {
) -> Result<Self, <Self as TryFromDataBytes>::Error> { ) -> Result<Self, <Self as TryFromDataBytes>::Error> {
Self::try_from_bytes(b.into_bytes(), format) Self::try_from_bytes(b.into_bytes(), format)
} }
fn apply<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self; fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self;
} }
pub trait IntoDataBytes: Sized { pub trait IntoDataBytes: Sized {