polished_css/data_type/
lightness.rs

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