Skip to main content

Readable

Trait Readable 

Source
pub trait Readable: Send + Sync {
    type Family: Family;
    type Digest: Digest;
    type Error;

    // Required methods
    fn size(&self) -> Position<Self::Family>;
    fn get_node(&self, pos: Position<Self::Family>) -> Option<Self::Digest>;
    fn root(&self) -> Self::Digest;
    fn pruning_boundary(&self) -> Location<Self::Family>;
    fn proof(
        &self,
        hasher: &impl Hasher<Self::Family, Digest = Self::Digest>,
        loc: Location<Self::Family>,
    ) -> Result<Proof<Self::Family, Self::Digest>, Self::Error>;
    fn range_proof(
        &self,
        hasher: &impl Hasher<Self::Family, Digest = Self::Digest>,
        range: Range<Location<Self::Family>>,
    ) -> Result<Proof<Self::Family, Self::Digest>, Self::Error>;

    // Provided methods
    fn leaves(&self) -> Location<Self::Family> { ... }
    fn bounds(&self) -> Range<Location<Self::Family>> { ... }
}
Expand description

Read-only interface for a merkleized data structure.

Required Associated Types§

Source

type Family: Family

The Merkle family implemented by this structure.

Source

type Digest: Digest

The digest type used by this structure.

Source

type Error

The error type returned by proof construction.

Required Methods§

Source

fn size(&self) -> Position<Self::Family>

Total number of nodes (retained + pruned).

Source

fn get_node(&self, pos: Position<Self::Family>) -> Option<Self::Digest>

Digest of the node at pos, or None if pruned / out of bounds.

Source

fn root(&self) -> Self::Digest

Root digest of the structure.

Source

fn pruning_boundary(&self) -> Location<Self::Family>

Leaf location up to which pruning has been performed, or 0 if never pruned.

Source

fn proof( &self, hasher: &impl Hasher<Self::Family, Digest = Self::Digest>, loc: Location<Self::Family>, ) -> Result<Proof<Self::Family, Self::Digest>, Self::Error>

Inclusion proof for the element at loc.

Source

fn range_proof( &self, hasher: &impl Hasher<Self::Family, Digest = Self::Digest>, range: Range<Location<Self::Family>>, ) -> Result<Proof<Self::Family, Self::Digest>, Self::Error>

Inclusion proof for all elements in range.

Provided Methods§

Source

fn leaves(&self) -> Location<Self::Family>

Total number of leaves.

Source

fn bounds(&self) -> Range<Location<Self::Family>>

[start, end) range of retained leaf locations.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Readable> Readable for Arc<T>

Source§

type Family = <T as Readable>::Family

Source§

type Digest = <T as Readable>::Digest

Source§

type Error = <T as Readable>::Error

Source§

fn size(&self) -> Position<Self::Family>

Source§

fn get_node(&self, pos: Position<Self::Family>) -> Option<Self::Digest>

Source§

fn root(&self) -> Self::Digest

Source§

fn pruning_boundary(&self) -> Location<Self::Family>

Source§

fn proof( &self, hasher: &impl Hasher<Self::Family, Digest = Self::Digest>, loc: Location<Self::Family>, ) -> Result<Proof<Self::Family, Self::Digest>, Self::Error>

Source§

fn range_proof( &self, hasher: &impl Hasher<Self::Family, Digest = Self::Digest>, range: Range<Location<Self::Family>>, ) -> Result<Proof<Self::Family, Self::Digest>, Self::Error>

Implementors§

Source§

impl<F: Family, D: Digest> Readable for commonware_storage::merkle::batch::MerkleizedBatch<F, D>

Source§

impl<F: Family, D: Digest> Readable for Mem<F, D>

Source§

impl<F: Family, D: Digest, Item: Send + Sync> Readable for commonware_storage::journal::authenticated::MerkleizedBatch<F, D, Item>

Source§

impl<F: Family, E: RStorage + Clock + Metrics, D: Digest> Readable for Journaled<F, E, D>

The Readable implementation for the journaled structure operates only on the in-memory portion. After Journaled::sync, nodes that have been flushed to the journal are no longer accessible through this interface. In particular, Readable::get_node returns None for flushed positions, and Readable::pruning_boundary reflects the in-memory boundary (which may be tighter than the journal’s prune boundary reported by Journaled::bounds). This means batch operations like update_leaf will correctly reject leaves that have been synced out of memory with Error::ElementPruned.