Add HtmlAttrs::{get, push_front}

This commit is contained in:
Laurenz 2025-07-15 10:45:25 +02:00
parent 32d51ae6d1
commit cf327650ba

View File

@ -172,10 +172,20 @@ impl HtmlAttrs {
Self::default() Self::default()
} }
/// Add an attribute. /// Adds an attribute.
pub fn push(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) { pub fn push(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) {
self.0.push((attr, value.into())); self.0.push((attr, value.into()));
} }
/// Adds an attribute to the start of the list.
pub fn push_front(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) {
self.0.insert(0, (attr, value.into()));
}
/// Finds an attribute value.
pub fn get(&self, attr: HtmlAttr) -> Option<&EcoString> {
self.0.iter().find(|&&(k, _)| k == attr).map(|(_, v)| v)
}
} }
cast! { cast! {