polished_css/data_type/
string.rs

1/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/string)
2/// [CSSWG specification](https://drafts.csswg.org/css-values/#string)
3/// NOTE: Is prefixed with `DataType`
4/// to avoid naming pitfalls with Rust's literal `String`.
5#[derive(Clone, PartialEq, Debug, polished_css_macros::Deref, polished_css_macros::Display)]
6pub struct DataTypeString(pub String);
7
8impl From<&str> for DataTypeString {
9    fn from(value: &str) -> Self {
10        Self(value.to_string())
11    }
12}
13
14pub trait StringStorage: From<DataTypeString> {
15    #[must_use]
16    fn string(value: &str) -> Self
17    where
18        Self: Sized,
19    {
20        Self::from(value.into())
21    }
22}
23
24#[cfg(test)]
25mod test {
26    #[test]
27    fn display() {
28        assert_eq!(
29            super::DataTypeString::from("it").to_string(),
30            String::from("it")
31        );
32        assert_eq!(
33            super::DataTypeString(String::from("works")).to_string(),
34            String::from("works")
35        );
36    }
37}