polished_css/data_type/
chroma.rs1use 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 }
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}