use crate::vdom::Value;
use std::borrow::Cow;
use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub struct Style {
pub name: Cow<'static, str>,
pub value: Value,
}
impl Style {
pub fn new(name: impl Into<Cow<'static, str>>, value: impl Into<Value>) -> Self {
Style {
name: name.into(),
value: value.into(),
}
}
pub(crate) fn merge_to_string<'a>(
styles: impl IntoIterator<Item = &'a Self>,
) -> Option<String> {
let stringed = styles
.into_iter()
.map(|s| format!("{s};"))
.collect::<Vec<_>>();
if !stringed.is_empty() {
let joined = stringed.join("");
Some(joined)
} else {
None
}
}
}
impl fmt::Display for Style {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}:{}", self.name, self.value)
}
}