Trait bao_tree::io::fsm::Outboard

source ·
pub trait Outboard {
    type LoadFuture<'a>: Future<Output = Result<Option<(Hash, Hash)>>>
       where Self: 'a;

    // Required methods
    fn root(&self) -> Hash;
    fn tree(&self) -> BaoTree;
    fn load(&mut self, node: TreeNode) -> Self::LoadFuture<'_>;
}
Expand description

A binary merkle tree for blake3 hashes of a blob.

This trait contains information about the geometry of the tree, the root hash, and a method to load the hashes at a given node.

It is up to the implementor to decide how to store the hashes.

In the original bao crate, the hashes are stored in a file in pre order. This is implemented for a generic io object in super::outboard::PreOrderOutboard and for a memory region in super::outboard::PreOrderMemOutboard.

For files that grow over time, it is more efficient to store the hashes in post order. This is implemented for a generic io object in super::outboard::PostOrderOutboard and for a memory region in super::outboard::PostOrderMemOutboard.

If you use a different storage engine, you can implement this trait for it. E.g. you could store the hashes in a database and use the node number as the key.

The async version takes a mutable reference to load, not because it mutates the outboard (it doesn’t), but to ensure that there is at most one outstanding load at a time.

Dropping the load future without polling it to completion is safe, but will possibly render the outboard unusable.

Required Associated Types§

source

type LoadFuture<'a>: Future<Output = Result<Option<(Hash, Hash)>>> where Self: 'a

Future returned by load

Required Methods§

source

fn root(&self) -> Hash

The root hash

source

fn tree(&self) -> BaoTree

The tree. This contains the information about the size of the file and the block size.

source

fn load(&mut self, node: TreeNode) -> Self::LoadFuture<'_>

load the hash pair for a node

This takes a &mut self not because it mutates the outboard (it doesn’t), but to ensure that there is only one outstanding load at a time.

Implementations on Foreign Types§

source§

impl<'b, O: Outboard> Outboard for &'b mut O

§

type LoadFuture<'a> = <O as Outboard>::LoadFuture<'a> where O: 'a, 'b: 'a

source§

fn root(&self) -> Hash

source§

fn tree(&self) -> BaoTree

source§

fn load(&mut self, node: TreeNode) -> Self::LoadFuture<'_>

Implementors§

source§

impl Outboard for EmptyOutboard

§

type LoadFuture<'a> = Ready<Result<Option<(Hash, Hash)>, Error>>

source§

impl<R: AsyncSliceReader> Outboard for PostOrderOutboard<R>

§

type LoadFuture<'a> = Pin<Box<dyn Future<Output = Result<Option<(Hash, Hash)>, Error>> + 'a, Global>> where R: 'a

source§

impl<R: AsyncSliceReader> Outboard for PreOrderOutboard<R>

§

type LoadFuture<'a> = Pin<Box<dyn Future<Output = Result<Option<(Hash, Hash)>, Error>> + 'a, Global>> where R: 'a

source§

impl<T: AsRef<[u8]> + 'static> Outboard for PreOrderMemOutboard<T>

§

type LoadFuture<'a> = Ready<Result<Option<(Hash, Hash)>, Error>>

source§

impl<T: AsRef<[u8]>> Outboard for PostOrderMemOutboard<T>

§

type LoadFuture<'a> = Ready<Result<Option<(Hash, Hash)>, Error>> where T: 'a