cssificator/
lib.rs

1use std::fmt::{Display, Formatter, Result};
2pub use style::Style;
3
4mod style;
5
6/// The base CSS struct which hoists a collection of styles
7pub struct CSS {
8    styles: Vec<Style>,
9}
10
11impl CSS {
12    /// Creates and returns an empty CSS struct
13    pub fn new() -> Self {
14        CSS { styles: vec![] }
15    }
16
17    /// Adds a style rule to the CSS struct
18    pub fn add_style(&mut self, style: Style) {
19        self.styles.push(style);
20    }
21}
22
23impl Display for CSS {
24    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
25        write!(
26            f,
27            "{}",
28            self.styles
29                .iter()
30                .map(|x| format!("{}", x))
31                .collect::<Vec<String>>()
32                .join("\n\n")
33        )
34    }
35}