From 916bea5eb2ee8f4f10adcb9f4853cc30253f96bb Mon Sep 17 00:00:00 2001 From: arabian Date: Fri, 9 May 2025 22:58:35 +0300 Subject: [PATCH] impl Display for Rgb and Hsl --- src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0640309..163ced8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,12 +6,24 @@ pub struct Hsl { 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 r: u8, pub g: 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 rgb: Rgb, pub hsl: Hsl, @@ -19,7 +31,7 @@ pub struct Color { } impl Color { - fn new(rgb: Rgb, proportion: f32) -> Color { + pub fn new(rgb: Rgb, proportion: f32) -> Color { let hsl = rgb_to_hsl(&rgb); Color { rgb,