pub trait HasGray {
type Component;
#[must_use]
fn new_gray(value: Self::Component) -> Self
where
Self: Sized + Default,
{
let mut color = Self::default();
color.set_gray(value);
color
}
#[must_use]
fn gray(&self) -> Self::Component;
fn set_gray(&mut self, value: Self::Component);
#[must_use]
fn with_gray(self, value: Self::Component) -> Self
where
Self: Sized,
{
let mut color = self;
color.set_gray(value);
color
}
}
#[cfg(test)]
#[allow(clippy::float_cmp)]
mod tests {
use crate::gray::GrayAlpha8;
use super::*;
#[test]
fn with_gray_grayalpha8_new_gray() {
assert_eq!(GrayAlpha8::new_gray(128), GrayAlpha8::new(128, 0));
}
#[test]
fn with_gray_grayalpha8_get_gray() {
assert_eq!(GrayAlpha8::new(128, 255).gray(), 128);
}
#[test]
fn with_gray_grayalpha8_set_gray() {
let mut color = GrayAlpha8::new(128, 255);
color.set_gray(64);
assert_eq!(color, GrayAlpha8::new(64, 255));
}
#[test]
fn with_gray_grayalpha8_with_gray() {
let color = GrayAlpha8::new(255, 255);
let new_color = color.with_gray(64);
assert_eq!(new_color, GrayAlpha8::new(64, 255));
}
}