use rand::Rng;
pub fn clean_string(s: &str) -> String
{
s.to_lowercase().replace(" ", "")
}
pub fn get_hsl(t: (u8, u8, u8)) -> colorsys::Hsl
{
let rgb = colorsys::Rgb::from
(
(
f64::from(t.0),
f64::from(t.1),
f64::from(t.2)
)
);
colorsys::Hsl::from(&rgb)
}
pub fn get_rgb_tuple_from_hsl(hsl: &colorsys::Hsl) -> (u8, u8, u8)
{
let rgb = colorsys::Rgb::from(hsl);
(
rgb.get_red().round() as u8,
rgb.get_green().round() as u8,
rgb.get_blue().round() as u8
)
}
pub fn round_float(n: f64) -> f64
{
(n * 100.0).round() / 100.0
}
pub fn random_u8() -> u8
{
let mut rng = rand::thread_rng();
let n: u8 = rng.gen(); n
}
#[cfg(test)]
mod tests
{
use super::*;
#[test]
fn utils_test()
{
assert_eq!(clean_string("A momenT Lapse"), "amomentlapse");
assert_eq!(round_float(40.842135), 40.84);
random_u8();
}
}