use anyhow::{format_err, Result};
use futures::future::BoxFuture;
use crate::node_type::{LeafNode, Node, NodeKey};
pub trait TreeReader: Send + Sync {
fn get_node_option<'future, 'a: 'future, 'n: 'future>(
&'a self,
node_key: &'n NodeKey,
) -> BoxFuture<'future, Result<Option<Node>>>;
#[allow(clippy::type_complexity)]
fn get_rightmost_leaf<'future, 'a: 'future>(
&'a self,
) -> BoxFuture<'future, Result<Option<(NodeKey, LeafNode)>>>;
}
pub async fn get_node_async<R: TreeReader>(reader: &R, node_key: &NodeKey) -> Result<Node> {
reader
.get_node_option(node_key)
.await?
.ok_or_else(|| format_err!("Missing node at {:?}.", node_key))
}