pub trait HasRed {
type Component;
#[must_use]
fn red(&self) -> Self::Component;
fn set_red(&mut self, value: Self::Component);
#[must_use]
fn with_red(self, value: Self::Component) -> Self
where
Self: Copy + Clone,
{
let mut color = self;
color.set_red(value);
color
}
}
#[cfg(test)]
#[allow(clippy::float_cmp)]
mod tests {
use crate::rgb::Rgb888;
use super::*;
#[test]
fn with_red_rgb888_get_red() {
assert_eq!(Rgb888::from_rgb(255, 0, 0).red(), 255);
}
#[test]
fn with_red_rgb888_set_red() {
let mut color = Rgb888::from_rgb(255, 0, 0);
color.set_red(128);
assert_eq!(color, Rgb888::from_rgb(128, 0, 0));
}
#[test]
fn with_red_rgb888_with_red() {
let color = Rgb888::from_rgb(255, 0, 0);
let new_color = color.with_red(128);
assert_eq!(new_color, Rgb888::from_rgb(128, 0, 0));
}
}