colorsys 0.7.3

A module for color conversion and mutation. Works with RGB(a)( as hexadecimal too), HSL(a), CMYK color models and with ANSI color codes
Documentation
#[cfg(not(feature = "std"))]
use alloc::string::String;
use crate::{normalize::round_ratio, ColorTupleA};
use crate::common::{f64_abs, f64_round};

pub fn tuple_to_string(tuple: &ColorTupleA, prefix: &str) -> String {
  use core::fmt::Write;

  let (x, y, z, a) = tuple;
  let mut start = String::from(prefix);
  let a = if f64_abs(a - 1.0) < f64::EPSILON {
    String::from("1")
  } else {
    format!("{}", round_ratio(*a))
  };

  let is_hsl = prefix == "hsl";
  let mut result = String::new();
  [x, y, z]
    .iter()
    .enumerate()
    .for_each(|(ind, u)| {
      let _ = write!(result, "{}", f64_round(**u));
      if is_hsl && (ind == 1 || ind == 2) {
        result.push('%');
      }
      if ind != 2 {
        result.push(',');
      }
    });

  if a != "1" {
    start.push('a');
    result.push(',');
    result.push_str(&a);
  }

  format!("{}({})", start, result)
}