pub trait HasBlue {
type Component;
#[must_use]
fn blue(&self) -> Self::Component;
fn set_blue(&mut self, value: Self::Component);
#[must_use]
fn with_blue(self, value: Self::Component) -> Self
where
Self: Copy + Clone,
{
let mut color = self;
color.set_blue(value);
color
}
}
#[cfg(test)]
#[allow(clippy::float_cmp)]
mod tests {
use crate::rgb::Rgb888;
use super::*;
#[test]
fn with_blue_rgb888_get_blue() {
assert_eq!(Rgb888::from_rgb(0, 0, 255).blue(), 255);
}
#[test]
fn with_blue_rgb888_set_blue() {
let mut color = Rgb888::from_rgb(0, 0, 255);
color.set_blue(128);
assert_eq!(color, Rgb888::from_rgb(0, 0, 128));
}
#[test]
fn with_blue_rgb888_with_blue() {
let color = Rgb888::from_rgb(0, 0, 255);
let new_color = color.with_blue(128);
assert_eq!(new_color, Rgb888::from_rgb(0, 0, 128));
}
}