Struct bridgetree::Frontier

source ·
pub struct Frontier<H, const DEPTH: u8> { /* private fields */ }
Expand description

A possibly-empty Merkle frontier.

Implementations§

source§

impl<H, const DEPTH: u8> Frontier<H, DEPTH>

source

pub fn empty() -> Frontier<H, DEPTH>

Constructs a new empty frontier.

source

pub fn from_parts( position: Position, leaf: H, ommers: Vec<H, Global> ) -> Result<Frontier<H, DEPTH>, FrontierError>

Constructs a new frontier from its constituent parts.

Returns an error if the new frontier would exceed the maximum allowed depth or if the list of ommers provided is not consistent with the position of the leaf.

source

pub fn value(&self) -> Option<&NonEmptyFrontier<H>>

Return the wrapped NonEmptyFrontier reference, or None if the frontier is empty.

source

pub fn take(self) -> Option<NonEmptyFrontier<H>>

Consumes this wrapper and returns the underlying Option<NonEmptyFrontier>

source

pub fn dynamic_memory_usage(&self) -> usize

Returns the amount of memory dynamically allocated for ommer values within the frontier.

source§

impl<H, const DEPTH: u8> Frontier<H, DEPTH>where H: Hashable + Clone,

source

pub fn append(&mut self, value: H) -> bool

Appends a new value to the frontier at the next available slot. Returns true if successful and false if the frontier would exceed the maximum allowed depth.

source

pub fn root(&self) -> H

Obtains the current root of this Merkle frontier by hashing against empty nodes up to the maximum height of the pruned tree that the frontier represents.

source

pub fn witness<F>( &self, complement_nodes: F ) -> Result<Option<MerklePath<H, DEPTH>>, Address>where F: Fn(Address) -> Option<H>,

Constructs a MerklePath to the leaf at the tip of this frontier, given a source of node values that complement this frontier.

If the complement_nodes function returns None when the value is requested at a given tree address, the address at which the failure occurs will be returned as an error.

Returns Ok(Some(MerklePath)) if successful, Ok(None) if the frontier is empty, or an error containing the address of the failure.

Trait Implementations§

source§

impl<H, const DEPTH: u8> Clone for Frontier<H, DEPTH>where H: Clone,

source§

fn clone(&self) -> Frontier<H, DEPTH>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<H, const DEPTH: u8> Debug for Frontier<H, DEPTH>where H: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<H, const DEPTH: u8> PartialEq<Frontier<H, DEPTH>> for Frontier<H, DEPTH>where H: PartialEq<H>,

source§

fn eq(&self, other: &Frontier<H, DEPTH>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<H, const DEPTH: u8> TryFrom<NonEmptyFrontier<H>> for Frontier<H, DEPTH>

§

type Error = FrontierError

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

fn try_from(f: NonEmptyFrontier<H>) -> Result<Frontier<H, DEPTH>, FrontierError>

Performs the conversion.
source§

impl<H, const DEPTH: u8> Eq for Frontier<H, DEPTH>where H: Eq,

source§

impl<H, const DEPTH: u8> StructuralEq for Frontier<H, DEPTH>

source§

impl<H, const DEPTH: u8> StructuralPartialEq for Frontier<H, DEPTH>

Auto Trait Implementations§

§

impl<H, const DEPTH: u8> RefUnwindSafe for Frontier<H, DEPTH>where H: RefUnwindSafe,

§

impl<H, const DEPTH: u8> Send for Frontier<H, DEPTH>where H: Send,

§

impl<H, const DEPTH: u8> Sync for Frontier<H, DEPTH>where H: Sync,

§

impl<H, const DEPTH: u8> Unpin for Frontier<H, DEPTH>where H: Unpin,

§

impl<H, const DEPTH: u8> UnwindSafe for Frontier<H, DEPTH>where H: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.