duid_core/core/html/attributes/
style.rs1use crate::core::html::attributes::Value;
2use std::fmt;
3
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct Style {
7 pub name: String,
8 pub value: Value,
9}
10
11impl Style {
12 pub fn new(name: impl ToString, value: impl Into<Value>) -> Self {
13 Style {
14 name: name.to_string(),
15 value: value.into(),
16 }
17 }
18}
19
20impl fmt::Display for Style {
21 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22 if self.name.len() == 0 {
23 write!(f, "{}", self.value)
24 }
25 else {
26 write!(f, "{}:{}", self.name, self.value)
27 }
28 }
29}