1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq)]
9pub struct CssVar(String);
10
11impl CssVar {
12 pub fn new(name: &str) -> Self {
14 let trimmed = name.trim();
15 let name = if trimmed.starts_with("--") {
16 trimmed.to_string()
17 } else {
18 format!("--{}", trimmed)
19 };
20 Self(name)
21 }
22}
23
24impl fmt::Display for CssVar {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "var({})", self.0)
27 }
28}
29
30pub fn var(name: &str) -> CssVar {
32 CssVar::new(name)
33}