polished_css/data_type/
chroma.rs

1use crate::prelude::NumberStorage;
2
3use super::{Number, Percentage};
4
5#[derive(
6    Clone,
7    Debug,
8    PartialEq,
9    strum_macros::EnumIs,
10    polished_css_macros::Display,
11    polished_css_macros::DataTypeFromDataTypes,
12)]
13#[display(on_enum = true)]
14pub enum Chroma {
15    Number(Number),
16    Percentage(Percentage),
17    None,
18}
19
20impl From<f64> for Chroma {
21    fn from(value: f64) -> Self {
22        Self::number(value)
23    }
24}
25
26#[polished_css_macros::create_trait_from_enum_impl()]
27impl Chroma {
28    // TODO: Add bounds to override number and percentage methods
29    // number can be only between 0 and 0.4 (interesting case!)
30    // percentage from 0% - 0 and 100% for 0.4
31
32    // TODO: Add conversion methods?
33}
34
35#[cfg(test)]
36mod test {
37    #[test]
38    fn display() {
39        use crate::data_type::{NumberStorage, PercentageStorage};
40        assert_eq!(super::Chroma::from(6.66).to_string(), String::from("6.66"));
41        assert_eq!(
42            super::Chroma::percentage(1.23).to_string(),
43            String::from("1.23%")
44        );
45        assert_eq!(super::Chroma::number(0.4).to_string(), String::from("0.4"));
46        assert_eq!(super::Chroma::None.to_string(), String::from("none"));
47    }
48}