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
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
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.
Fields
value: TImplementations§
Source§impl<T: Storable + CondSync> Link<T>
impl<T: Storable + CondSync> Link<T>
Sourcepub async fn resolve_cid(&self, store: &impl BlockStore) -> Result<Cid>
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.
Sourcepub async fn resolve_value(&self, store: &impl BlockStore) -> Result<&T>
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.
Sourcepub async fn resolve_value_mut(
&mut self,
store: &impl BlockStore,
) -> Result<&mut T>
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.
Sourcepub fn get_cid(&self) -> Option<&Cid>
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..
Sourcepub fn get_value(&self) -> Option<&T>
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.
Sourcepub async fn resolve_owned_value(self, store: &impl BlockStore) -> Result<T>where
T: Storable,
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.