pub struct WalkMut<'r, T: ?Sized, N: ?Sized, A = ()> { /* private fields */ }
Expand description
Walk tree structures without call stack
Walking tree structures with mutable references usually requires a recursive call stack to make the borrow-checker happy.
This uses a stack (Vec
) to keep track of the “current”
mutable reference (and hiding the previous ones).
(There is no way to implement this without unsafe
, but the
abstraction should be safe.)
Each nested level can also track additional value of type A
.
Implementations§
source§impl<'r, T: ?Sized, N: ?Sized, A> WalkMut<'r, T, N, A>
impl<'r, T: ?Sized, N: ?Sized, A> WalkMut<'r, T, N, A>
sourcepub fn try_walk<F, E>(&mut self, with: F) -> Result<(), E>
pub fn try_walk<F, E>(&mut self, with: F) -> Result<(), E>
Walk down the tree one step
The step can fail by returning Err
.
sourcepub fn pop(&mut self) -> Option<A>
pub fn pop(&mut self) -> Option<A>
Walk up to the previous level.
Returns the associated data stored with the step,
or None
if already at the initial tree.
sourcepub fn current_mut(&mut self) -> NodeOrTree<&mut T, &mut N>
pub fn current_mut(&mut self) -> NodeOrTree<&mut T, &mut N>
Get mutable reference to current node or tree
If you need the result to outlive the destruction of the WalkMut
value, see into_current_mut
.
sourcepub fn into_current_mut(self) -> NodeOrTree<&'r mut T, &'r mut N>
pub fn into_current_mut(self) -> NodeOrTree<&'r mut T, &'r mut N>
Extract mutable reference to current node or tree
Also see current_mut
sourcepub fn into_tree_mut(self) -> &'r mut T
pub fn into_tree_mut(self) -> &'r mut T
Extract mutable reference to tree
sourcepub fn current(&self) -> NodeOrTree<&T, &N>
pub fn current(&self) -> NodeOrTree<&T, &N>
Get reference to current node or tree