1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Walk

#[cfg(feature = "full")]
use grovedb_costs::CostResult;
use grovedb_version::version::GroveVersion;

#[cfg(feature = "full")]
use super::super::{Link, TreeNode};
#[cfg(feature = "full")]
use crate::error::Error;
#[cfg(feature = "full")]
use crate::tree::kv::ValueDefinedCostType;

#[cfg(feature = "full")]
/// A source of data to be used by the tree when encountering a pruned node.
/// This typically means fetching the tree node from a backing store by its key,
/// but could also implement an in-memory cache for example.
pub trait Fetch {
    /// Called when the tree needs to fetch a node with the given `Link`. The
    /// `link` value will always be a `Link::Reference` variant.
    fn fetch(
        &self,
        link: &Link,
        value_defined_cost_fn: Option<
            &impl Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
        >,
        grove_version: &GroveVersion,
    ) -> CostResult<TreeNode, Error>;
}