pub trait DriveMut: Any {
    fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V);
}
Expand description

Drive a VisitorMut over this datastructure.

This is equivalent to Drive, but gives the possibility to mutate the datastructure as it is visited.

Example

use derive_visitor::{DriveMut, Event, visitor_fn_mut};

#[derive(DriveMut, Default)]
struct Node{ children: Vec<Node> }

let mut node = Node{children: vec![Node::default(), Node::default()]};

node.drive_mut(&mut visitor_fn_mut(|n: &mut Node, event|
    // Mutate the element on exit so that we are not driven to the newly created elements
    if let Event::Exit = event {
        n.children.resize_with(3, Default::default);
    }
));

// We have driven over all the initial nodes...
assert_eq!(node.children.len(), 3);
assert_eq!(node.children[0].children.len(), 3);
assert_eq!(node.children[1].children.len(), 3);
// ... but not over the newly created ones
assert_eq!(node.children[2].children.len(), 0);

Required Methods

Implementations on Foreign Types

Implementors