//! Async read-only trait for merkleized data structures. use crate::merkle::{mem::Mem, Error, Family, Position}; use commonware_cryptography::Digest; use core::future::Future; /// An async trait for accessing Merkle node digests from storage. pub trait Storage: Send + Sync { /// The digest type used by this storage. type Digest: Digest; /// Return the number of nodes in the structure. fn size(&self) -> impl Future> + Send; /// Return the specified node of the structure if it exists and hasn't been pruned. fn get_node( &self, position: Position, ) -> impl Future, Error>> + Send; } impl Storage for Mem where F: Family, D: Digest, { type Digest = D; async fn size(&self) -> Position { self.size() } async fn get_node(&self, position: Position) -> Result, Error> { Ok(Self::get_node(self, position)) } }