polished_css/data_type/
integer.rs

1/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/integer)
2/// [CSSWG specification](https://drafts.csswg.org/css-values/#integer)
3#[derive(Clone, PartialEq, Debug, polished_css_macros::Deref, polished_css_macros::Display)]
4pub struct Integer(pub isize);
5
6impl Integer {
7    #[must_use]
8    pub fn zero() -> Self {
9        Self(0)
10    }
11}
12
13pub trait IntegerStorage: From<Integer> {
14    #[must_use]
15    fn integer(value: isize) -> Self {
16        Self::from(Integer(value))
17    }
18
19    #[must_use]
20    fn zero() -> Self {
21        Self::integer(0)
22    }
23}
24
25#[cfg(test)]
26mod test {
27    #[test]
28    fn display() {
29        assert_eq!(super::Integer(1).to_string(), String::from("1"));
30        assert_eq!(super::Integer(-1).to_string(), String::from("-1"));
31        assert_eq!(super::Integer::zero().to_string(), String::from("0"));
32    }
33}