Trait derive_visitor::DriveMut

source ·
pub trait DriveMut: Any {
    // Required method
    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§

source

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl DriveMut for ()

source§

fn drive_mut<V: VisitorMut>(&mut self, _visitor: &mut V)

source§

impl<T0> DriveMut for (T0,)
where T0: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1> DriveMut for (T0, T1)
where T0: DriveMut, T1: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1, T2> DriveMut for (T0, T1, T2)
where T0: DriveMut, T1: DriveMut, T2: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1, T2, T3> DriveMut for (T0, T1, T2, T3)
where T0: DriveMut, T1: DriveMut, T2: DriveMut, T3: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1, T2, T3, T4> DriveMut for (T0, T1, T2, T3, T4)
where T0: DriveMut, T1: DriveMut, T2: DriveMut, T3: DriveMut, T4: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1, T2, T3, T4, T5> DriveMut for (T0, T1, T2, T3, T4, T5)
where T0: DriveMut, T1: DriveMut, T2: DriveMut, T3: DriveMut, T4: DriveMut, T5: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1, T2, T3, T4, T5, T6> DriveMut for (T0, T1, T2, T3, T4, T5, T6)
where T0: DriveMut, T1: DriveMut, T2: DriveMut, T3: DriveMut, T4: DriveMut, T5: DriveMut, T6: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7> DriveMut for (T0, T1, T2, T3, T4, T5, T6, T7)
where T0: DriveMut, T1: DriveMut, T2: DriveMut, T3: DriveMut, T4: DriveMut, T5: DriveMut, T6: DriveMut, T7: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for Option<T>
where Option<T>: 'static, for<'a> &'a mut Option<T>: IntoIterator, for<'a> <&'a mut Option<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for [T]
where [T]: 'static, for<'a> &'a mut [T]: IntoIterator, for<'a> <&'a mut [T] as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for Box<T>
where T: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for BinaryHeap<T>
where BinaryHeap<T>: 'static, for<'a> &'a mut BinaryHeap<T>: IntoIterator, for<'a> <&'a mut BinaryHeap<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for BTreeSet<T>
where BTreeSet<T>: 'static, for<'a> &'a mut BTreeSet<T>: IntoIterator, for<'a> <&'a mut BTreeSet<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for LinkedList<T>
where LinkedList<T>: 'static, for<'a> &'a mut LinkedList<T>: IntoIterator, for<'a> <&'a mut LinkedList<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for VecDeque<T>
where VecDeque<T>: 'static, for<'a> &'a mut VecDeque<T>: IntoIterator, for<'a> <&'a mut VecDeque<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for Arc<Mutex<T>>
where T: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for Arc<RwLock<T>>
where T: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for Vec<T>
where Vec<T>: 'static, for<'a> &'a mut Vec<T>: IntoIterator, for<'a> <&'a mut Vec<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for Cell<T>
where T: DriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T> DriveMut for HashSet<T>
where HashSet<T>: 'static, for<'a> &'a mut HashSet<T>: IntoIterator, for<'a> <&'a mut HashSet<T> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T, U> DriveMut for Result<T, U>
where Result<T, U>: 'static, for<'a> &'a mut Result<T, U>: IntoIterator, for<'a> <&'a mut Result<T, U> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T, U> DriveMut for BTreeMap<T, U>
where BTreeMap<T, U>: 'static, for<'a> &'a mut BTreeMap<T, U>: IntoIterator, for<'a> <&'a mut BTreeMap<T, U> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T, U> DriveMut for HashMap<T, U>
where HashMap<T, U>: 'static, for<'a> &'a mut HashMap<T, U>: IntoIterator, for<'a> <&'a mut HashMap<T, U> as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<T, const N: usize> DriveMut for [T; N]
where [T; N]: 'static, for<'a> &'a mut [T; N]: IntoIterator, for<'a> <&'a mut [T; N] as IntoIterator>::Item: DerefAndDriveMut,

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

Implementors§