Enum wnfs_common::Link

source ·
pub enum Link<T> {
    Encoded {
        cid: Cid,
        value_cache: OnceCell<T>,
    },
    Decoded {
        value: T,
    },
}
Expand description

A data structure that represents a link in the IPLD graph. Basically it is a “link” to some content addressable value of T.

It supports representing the “link” with a Cid or the deserialized value itself.

Link needs a BlockStore to be able to resolve Cids to corresponding values of T and vice versa.

Variants§

§

Encoded

Fields

§cid: Cid
§value_cache: OnceCell<T>

A variant of Link that started out as a Cid. If the decoded value is resolved using resolve_value, then the value_cache gets populated and further calls to resolve_value will just return from that cache.

§

Decoded

Fields

§value: T

A variant of Link that started out as a deserialized value T. If the cid is resolved using resolve_cid, then T’s .persisted_as from the Storable trait is called and that OnceCell<Cid> is populated, preventing further calls to resolve_cid from duplicating work.

Implementations§

source§

impl<T: Storable + CondSync> Link<T>

source

pub fn from_cid(cid: Cid) -> Self

Creates a new Link that starts out as a Cid.

source

pub async fn resolve_cid(&self, store: &impl BlockStore) -> Result<Cid>

Gets the Cid stored in type. It attempts to get it from the store if it is not present in type.

source

pub async fn resolve_value(&self, store: &impl BlockStore) -> Result<&T>

Gets the value stored in link. It attempts to get it from the store if it is not present in link.

source

pub async fn resolve_value_mut( &mut self, store: &impl BlockStore ) -> Result<&mut T>

Gets mut value stored in link. It attempts to get it from the store if it is not present in link.

source

pub fn get_cid(&self) -> Option<&Cid>

Gets the cid data stored in type.

NOTE: This does not attempt to get it from the store if it does not exist..

source

pub fn get_value(&self) -> Option<&T>

Gets the value stored in type.

NOTE: This does not attempt to get it from the store if it does not exist.

source

pub async fn resolve_owned_value(self, store: &impl BlockStore) -> Result<T>
where T: Storable,

Gets an owned value from type. It attempts to it get from the store if it is not present in type.

source

pub fn has_cid(&self) -> bool

Checks if there is a Cid cached in link.

source

pub fn has_value(&self) -> bool

Checks if there is a value stored in link.

source

pub async fn deep_eq( &self, other: &Link<T>, store: &impl BlockStore ) -> Result<bool>
where T: PartialEq + Storable,

Compares two links for equality. Attempts to get them from store if they are not already cached.

Trait Implementations§

source§

impl<T> Clone for Link<T>
where T: Clone,

source§

fn clone(&self) -> Self

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 Link<T>
where T: Debug,

source§

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

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

impl<T: Storable> From<T> for Link<T>

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<T> PartialEq for Link<T>

source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Link<T>

§

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

§

impl<T> Sync for Link<T>
where T: Sync + Send,

§

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

§

impl<T> UnwindSafe for Link<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.

§

impl<T> References<RawCodec> for T

§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
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<S> CondSend for S
where S: Send,

source§

impl<S> CondSync for S
where S: Send + Sync,