From 5233d6af4434fab4f8c19baf24b12f6546500bba Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Fri, 7 Dec 2018 15:54:24 +0000 Subject: [PATCH] node: add attr_mut helper method --- src/node/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/node/mod.rs b/src/node/mod.rs index 5b55863..a8cb448 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -150,6 +150,11 @@ impl Node { self.attributes.as_ref() } + #[inline] + pub fn attributes_mut(&mut self) -> Option<&mut IndexMap> { + self.attributes.as_mut() + } + #[inline] pub fn children(&self) -> Option<&Vec> { 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) { (self.key, self.value) }