pub enum MaybePruned<T>
where T: Clone + Serialize,
{ Value(T), Pruned(Digest), }
Expand description

Either a source value or a hash Digest of the source value.

This type supports creating “Merkle-ized structs”. Each field of a Merkle-ized struct can have either the full value, or it can be “pruned” and replaced with a digest committing to that value. One way to think of this is as a special Merkle tree of a predefined shape. Each field is a child node. Any field/node in the tree can be opened by providing the Merkle inclusion proof. When a subtree is pruned, the digest commits to the value of all contained fields. ReceiptClaim is the motivating example of this type of Merkle-ized struct.

Variants§

§

Value(T)

Unpruned value.

§

Pruned(Digest)

Pruned value, which is a hash Digest of the value.

Implementations§

source§

impl MaybePruned<Assumptions>

source

pub fn is_empty(&self) -> bool

Check if the (possibly pruned) assumptions list is empty.

source

pub fn add(&mut self, assumption: MaybePruned<ReceiptClaim>)

Add an assumption to the head of the assumptions list.

If this value is pruned, then the result will also be a pruned value.

source

pub fn resolve(&mut self, resolved: &Digest, tail: &Digest) -> Result<()>

Mark an assumption as resolved and remove it from the list.

Assumptions can only be removed from the head of the list. If this value is pruned, then the result will also be a pruned value. The tail parameter should be equal to the digest of the list after the resolved assumption is removed.

source§

impl<T> MaybePruned<T>
where T: Clone + Serialize,

source

pub fn value(self) -> Result<T, PrunedValueError>

Unwrap the value, or return an error.

source

pub fn as_value(&self) -> Result<&T, PrunedValueError>

Unwrap the value as a reference, or return an error.

source

pub fn as_value_mut(&mut self) -> Result<&mut T, PrunedValueError>

Unwrap the value as a mutable reference, or return an error.

source§

impl<T> MaybePruned<Option<T>>
where T: Clone + Serialize,

source

pub fn is_none(&self) -> bool

Returns true is the value is None, or the value is pruned as the zero digest.

source

pub fn is_some(&self) -> bool

Returns true is the value is Some(_), or the value is pruned as a non-zero digest.

Trait Implementations§

source§

impl<T> Clone for MaybePruned<T>
where T: Clone + Serialize + Clone,

source§

fn clone(&self) -> MaybePruned<T>

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<T> Debug for MaybePruned<T>

source§

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

Format MaybePruned values are if they were a struct with value and digest fields. Digest field is always provided so that divergent trees of MaybePruned values can be compared.

source§

impl<T> Default for MaybePruned<T>

source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for MaybePruned<T>
where T: Clone + Serialize + Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Digestible for MaybePruned<T>
where T: Digestible + Clone + Serialize,

source§

fn digest<S: Sha256>(&self) -> Digest

Calculate a collision resistant hash for the typed and structured data.
source§

impl From<MaybePruned<ReceiptClaim>> for Assumption

source§

fn from(claim: MaybePruned<ReceiptClaim>) -> Self

Create an unresolved assumption from a MaybePruned ReceiptClaim.

source§

impl<T> From<T> for MaybePruned<T>
where T: Clone + Serialize,

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<T> Serialize for MaybePruned<T>
where T: Clone + Serialize + Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for MaybePruned<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<D> Digestible for D
where D: Digestible + ?Sized,

source§

fn digest(&self) -> Digest

Calculate a collision resistant hash for the typed and structured data.

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,