impl Display for Rgb and Hsl

This commit is contained in:
2025-05-09 22:58:35 +03:00
parent 3f4abaa97d
commit 916bea5eb2
+13 -1
View File
@@ -6,12 +6,24 @@ pub struct Hsl {
pub l: u8, pub l: u8,
} }
impl std::fmt::Display for Hsl {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "hsl({}, {}, {})", self.h, self.s, self.l)
}
}
pub struct Rgb { pub struct Rgb {
pub r: u8, pub r: u8,
pub g: u8, pub g: u8,
pub b: u8, pub b: u8,
} }
impl std::fmt::Display for Rgb {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "rgb({}, {}, {})", self.r, self.g, self.b)
}
}
pub struct Color { pub struct Color {
pub rgb: Rgb, pub rgb: Rgb,
pub hsl: Hsl, pub hsl: Hsl,
@@ -19,7 +31,7 @@ pub struct Color {
} }
impl Color { impl Color {
fn new(rgb: Rgb, proportion: f32) -> Color { pub fn new(rgb: Rgb, proportion: f32) -> Color {
let hsl = rgb_to_hsl(&rgb); let hsl = rgb_to_hsl(&rgb);
Color { Color {
rgb, rgb,