pub fn encode_attribute(name: &str, value: &Option<&dyn ToString>) -> Option<String> {
if value.is_none() {
return None;
}
value.map(|v| format!("{}=\"{}\"", name, v.to_string()))
}
pub fn encode_attributes(attrs: &[(&str, Option<&dyn ToString>)], enclosed: bool) -> Option<String> {
if attrs.is_empty() {
None
} else {
let encoded_attrs: Vec<String> = attrs
.iter()
.filter_map(|(name, value)| encode_attribute(name, value))
.collect();
if enclosed {
Some(format!("[{}]", encoded_attrs.join(" ")))
} else {
Some(encoded_attrs.join(" "))
}
}
}