small refactoring

This commit is contained in:
2026-01-06 05:12:35 +03:00
parent a5976d807e
commit 3dfdf0a91f
+11 -6
View File
@@ -1,4 +1,9 @@
use image; use image;
use std::{
error::Error,
fmt::{Display, Formatter, Result as fmtResult},
path::Path,
};
pub struct Hsl { pub struct Hsl {
pub h: u8, pub h: u8,
@@ -6,8 +11,8 @@ pub struct Hsl {
pub l: u8, pub l: u8,
} }
impl std::fmt::Display for Hsl { impl Display for Hsl {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmtResult {
write!(f, "hsl({}, {}, {})", self.h, self.s, self.l) write!(f, "hsl({}, {}, {})", self.h, self.s, self.l)
} }
} }
@@ -18,8 +23,8 @@ pub struct Rgb {
pub b: u8, pub b: u8,
} }
impl std::fmt::Display for Rgb { impl Display for Rgb {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmtResult {
write!(f, "rgb({}, {}, {})", self.r, self.g, self.b) write!(f, "rgb({}, {}, {})", self.r, self.g, self.b)
} }
} }
@@ -73,10 +78,10 @@ fn rgb_to_hsl(rgb: &Rgb) -> Hsl {
Hsl { h, s, l: l as u8 } Hsl { h, s, l: l as u8 }
} }
pub fn extract<P: AsRef<std::path::Path>>( pub fn extract<P: AsRef<Path>>(
path: P, path: P,
number_of_color: usize, number_of_color: usize,
) -> Result<Vec<Color>, Box<dyn std::error::Error>> { ) -> Result<Vec<Color>, Box<dyn Error>> {
let img = image::open(path)?; let img = image::open(path)?;
let img = img.to_rgb8(); let img = img.to_rgb8();