merkle_search_tree/visitor/trait.rs
1use crate::{node::Node, page::Page};
2
3/// An observer of [`Page`] and the [`Node`] instances within them during tree
4/// traversal.
5pub trait Visitor<'a, const N: usize, K> {
6 /// Called before a a call to [`Visitor::visit_node()`] with the same
7 /// [`Node`].
8 ///
9 /// By default this is a no-op unless implemented.
10 fn pre_visit_node(&mut self, node: &'a Node<N, K>) -> bool {
11 let _ = node;
12 true
13 }
14
15 /// Visit the given [`Node`].
16 fn visit_node(&mut self, node: &'a Node<N, K>) -> bool;
17
18 /// Called after [`Visitor::visit_node()`] with the same [`Node`].
19 ///
20 /// By default this is a no-op unless implemented.
21 fn post_visit_node(&mut self, node: &'a Node<N, K>) -> bool {
22 let _ = node;
23 true
24 }
25
26 /// Visit the given [`Page`], which was referenced via a high-page link if
27 /// `high_page` is true.
28 ///
29 /// By default this is a no-op unless implemented.
30 fn visit_page(&mut self, page: &'a Page<N, K>, high_page: bool) -> bool {
31 let _ = page;
32 let _ = high_page;
33 true
34 }
35
36 /// Called after [`Visitor::visit_page()`] with the same [`Page`].
37 ///
38 /// By default this is a no-op unless implemented.
39 fn post_visit_page(&mut self, page: &'a Page<N, K>) -> bool {
40 let _ = page;
41 true
42 }
43}