diff --git a/apb/src/node.rs b/apb/src/node.rs index 53b967ff..ce19419f 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -16,6 +16,9 @@ impl From> for Node { } } +// TODO how do i move out of the box for a moment? i need to leave it uninitialized while i update +// the value and then put it back, i think it should be safe to do so! but i'm not sure how, so i'm +// using a clone (expensive but simple solution) impl Iterator for Node { type Item = T; @@ -31,6 +34,14 @@ impl Iterator for Node { } } +impl Node { + pub fn update(&mut self, builder: impl FnOnce(T) -> T) { + if let Node::Object(x) = self { + *x = Box::new(builder((**x).clone())); + } + } +} + impl Node { /// return reference to embedded object (or last if many are present) pub fn get(&self) -> Option<&T> {