bitstring_trees::walk_mut

Struct WalkMut

source
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>

source

pub fn new(tree: &'r mut T) -> Self

Start a new tree walk at a tree

source

pub fn try_walk<F, E>(&mut self, with: F) -> Result<(), E>
where F: for<'n> FnOnce(NodeOrTree<&'n mut T, &'n mut N>) -> Result<(&'n mut N, A), E>,

Walk down the tree one step

The step can fail by returning Err.

source

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.

source

pub fn pop_all(&mut self) -> &mut T

Walk up to tree

source

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.

source

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

source

pub fn into_tree_mut(self) -> &'r mut T

Extract mutable reference to tree

source

pub fn current(&self) -> NodeOrTree<&T, &N>

Get reference to current node or tree

Auto Trait Implementations§

§

impl<'r, T, N, A> Freeze for WalkMut<'r, T, N, A>
where T: ?Sized, N: ?Sized,

§

impl<'r, T, N, A> RefUnwindSafe for WalkMut<'r, T, N, A>

§

impl<'r, T, N, A = ()> !Send for WalkMut<'r, T, N, A>

§

impl<'r, T, N, A = ()> !Sync for WalkMut<'r, T, N, A>

§

impl<'r, T, N, A> Unpin for WalkMut<'r, T, N, A>
where A: Unpin, T: ?Sized, N: ?Sized,

§

impl<'r, T, N, A = ()> !UnwindSafe for WalkMut<'r, T, N, A>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.