node: add attr_mut helper method

This commit is contained in:
Matt Bilker
2018-12-07 15:54:24 +00:00
parent d1b94c0bbf
commit 5233d6af44

View File

@@ -150,6 +150,11 @@ impl Node {
self.attributes.as_ref()
}
#[inline]
pub fn attributes_mut(&mut self) -> Option<&mut IndexMap<String, String>> {
self.attributes.as_mut()
}
#[inline]
pub fn children(&self) -> Option<&Vec<Node>> {
self.children.as_ref()
@@ -181,6 +186,12 @@ impl Node {
})
}
pub fn attr_mut(&mut self, key: &str) -> Option<&mut String> {
self.attributes_mut().and_then(|attributes| {
attributes.get_mut(key)
})
}
pub fn into_key_and_value(self) -> (String, Option<Value>) {
(self.key, self.value)
}