diff --git a/src/node.rs b/src/node.rs index 386f794..063bd45 100644 --- a/src/node.rs +++ b/src/node.rs @@ -189,6 +189,22 @@ impl Node { None } + /// Returns a mutable reference to the parent node of this node, + /// or None if it is the root node. Ensure that there is only one reference to the returned value. + /// Also see the `parent` method. + pub unsafe fn parent_mut( &self ) -> Option<&mut Node> { + let mut node = self.non_null(); + while let Some( parent ) = node.as_ref().up { + if parent.as_ref().is_forest() { + node = parent; + } else { + return Some( &mut *parent.as_ptr() ); + } + } + None + } + + /// Inserts sib tree before `self`. /// The newly inserted node will not be iterated over by the currently running iterator. ///