MerkleRootBuilder

Struct MerkleRootBuilder 

Source
pub struct MerkleRootBuilder<T> { /* private fields */ }
Expand description

Calculates the merkle root for a given set of data. The leaf hashes of the merkle tree can optionally be collected for use with crate::MerkleVerifier.

MerkleRootBuilder only accepts complete blocks of data except for the last block. This avoids buffering data internally. If complete blocks of data can’t be guaranteed then BufferedMerkleRootBuilder should be used instead.

Most users of crate::MerkleTreeBuilder are only interested in the root of the merkle tree but crate::MerkleTreeBuilder generates and keeps the entire tree in memory. It also buffers the hashes of inner nodes. MerkleRootBuilder is able to generate just the root using less memory and a lot less buffering.

Implementations§

Source§

impl<T: LeafHashCollector> MerkleRootBuilder<T>

Source

pub fn new(leaf_hash_collector: T) -> Self

Creates a new MerkleRootBuilder with a LeafHashCollector.

Use MerkleRootBuilder::default() if a LeafHashCollector isn’t needed.

Source

pub fn add_block(&mut self, data: &[u8; 8192])

Appends a full block of data to the merkle tree.

MerkleRootBuilder doesn’t buffer any data so only full blocks can be added until Self::complete is called. Use BufferedMerkleRootBuilder if buffering is required.

Source

pub fn complete(self, data: &[u8]) -> T::Output

Appends a final amount of data to the merkle tree and returns the merkle root.

Trait Implementations§

Source§

impl Default for MerkleRootBuilder<NoopLeafHashCollector>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MerkleRootBuilder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MerkleRootBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for MerkleRootBuilder<T>
where T: Send,

§

impl<T> Sync for MerkleRootBuilder<T>
where T: Sync,

§

impl<T> Unpin for MerkleRootBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for MerkleRootBuilder<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.