ntree_rs/traversal/traverse_mut/
mod.rs1#[cfg(feature = "async")]
4mod r#async;
5#[cfg(feature = "async")]
6pub use r#async::*;
7
8mod sync;
9pub use sync::*;
10
11use crate::{Asynchronous, Node, Synchronous};
12use std::marker::PhantomData;
13
14pub struct TraverseMut<'a, T, S> {
16 node: &'a mut Node<T>,
17 strategy: PhantomData<S>,
18}
19
20impl<'a, T, S> From<&'a mut Node<T>> for TraverseMut<'a, T, S> {
21 fn from(node: &'a mut Node<T>) -> Self {
22 Self {
23 node,
24 strategy: PhantomData,
25 }
26 }
27}
28
29impl<'a, T> From<TraverseMut<'a, T, Asynchronous>> for TraverseMut<'a, T, Synchronous> {
30 fn from(value: TraverseMut<'a, T, Asynchronous>) -> Self {
31 TraverseMut::new(value.node)
32 }
33}
34
35impl<'a, T> From<TraverseMut<'a, T, Synchronous>> for TraverseMut<'a, T, Asynchronous>
36where
37 T: Sync + Send,
38{
39 fn from(value: TraverseMut<'a, T, Synchronous>) -> Self {
40 TraverseMut::new_async(value.node)
41 }
42}
43impl<'a, T, S> TraverseMut<'a, T, S> {
44 pub fn node(&self) -> &Node<T> {
45 self.node
46 }
47
48 pub fn node_mut(&mut self) -> &mut Node<T> {
49 self.node
50 }
51
52 pub fn pre(self) -> InPreMut<'a, T, S> {
54 InPreMut {
55 node: self.node,
56 strategy: PhantomData,
57 }
58 }
59
60 pub fn post(self) -> InPostMut<'a, T, S> {
62 InPostMut {
63 node: self.node,
64 strategy: PhantomData,
65 }
66 }
67}
68
69pub struct InPreMut<'a, T, S> {
71 node: &'a mut Node<T>,
72 strategy: PhantomData<S>,
73}
74
75pub struct InPostMut<'a, T, S> {
77 node: &'a mut Node<T>,
78 strategy: PhantomData<S>,
79}
80
81pub struct PrePostMut<'a, T, R, F, S> {
83 node: &'a mut Node<T>,
84 pre: F,
85 r: PhantomData<R>,
86 strategy: PhantomData<S>,
87}