Struct noosphere_core::data::Link
source · #[repr(transparent)]pub struct Link<T>where
T: Clone,{
pub cid: Cid,
/* private fields */
}Expand description
A Link is a Cid with a type attached. The type represents the data that the Cid refers to. This is a helpful construct to use to ensure that data structures whose fields or elements may be Cids can still retain strong typing. A Link transparently represents its inner Cid, so a data structure that uses Links can safely be interpretted in terms of Cids, and vice-versa.
Fields§
§cid: CidImplementations§
source§impl<T> Link<T>where
T: Serialize + DeserializeOwned + Clone + LinkSend,
impl<T> Link<T>where T: Serialize + DeserializeOwned + Clone + LinkSend,
sourcepub async fn load_from<S: BlockStore>(&self, store: &S) -> Result<T>
pub async fn load_from<S: BlockStore>(&self, store: &S) -> Result<T>
Given a BlockStore, attempt to load a value for the Cid of this Link. The loaded block will be interpretted as the type that is attached to the Cid by this Link, and then returned.
Methods from Deref<Target = Cid>§
sourcepub fn write_bytes<W>(&self, w: W) -> Result<usize, Error>where
W: Write,
pub fn write_bytes<W>(&self, w: W) -> Result<usize, Error>where W: Write,
Writes the bytes to a byte stream, returns the number of bytes written.
sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Returns the length in bytes needed to encode this cid into bytes.
sourcepub fn to_string_of_base(&self, base: Base) -> Result<String, Error>
pub fn to_string_of_base(&self, base: Base) -> Result<String, Error>
Convert CID into a multibase encoded string
Example
use cid::Cid;
use multibase::Base;
use multihash::{Code, MultihashDigest};
const RAW: u64 = 0x55;
let cid = Cid::new_v1(RAW, Code::Sha2_256.digest(b"foo"));
let encoded = cid.to_string_of_base(Base::Base64).unwrap();
assert_eq!(encoded, "mAVUSICwmtGto/8aP+ZtFPB0wQTQTQi1wZIO/oPmKXohiZueu");Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Link<T>where
T: Clone,
impl<'de, T> Deserialize<'de> for Link<T>where T: Clone,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> Ord for Link<T>where
T: Clone + Ord,
impl<T> Ord for Link<T>where T: Clone + Ord,
source§impl<T> PartialEq<Link<T>> for Link<T>where
T: Clone,
impl<T> PartialEq<Link<T>> for Link<T>where T: Clone,
source§impl<T> PartialOrd<Link<T>> for Link<T>where
T: Clone + PartialOrd,
impl<T> PartialOrd<Link<T>> for Link<T>where T: Clone + PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl<T> TryBundle for Link<T>where
T: TryBundle + Clone,
impl<T> TryBundle for Link<T>where T: TryBundle + Clone,
fn extend_bundle<'life0, 'life1, 'life2, 'async_trait, S>( &'life0 self, bundle: &'life1 mut Bundle, store: &'life2 S ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where S: 'async_trait + BlockStore, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
fn extend_bundle_with_cid<'life0, 'life1, 'life2, 'async_trait, S>( cid: &'life0 Cid, bundle: &'life1 mut Bundle, store: &'life2 S ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where S: 'async_trait + BlockStore, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
fn bundle<'life0, 'life1, 'async_trait, S>( &'life0 self, store: &'life1 S ) -> Pin<Box<dyn Future<Output = Result<Bundle>> + Send + 'async_trait>>where S: 'async_trait + BlockStore, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
fn bundle_with_cid<'life0, 'life1, 'async_trait, S>( cid: &'life0 Cid, store: &'life1 S ) -> Pin<Box<dyn Future<Output = Result<Bundle>> + Send + 'async_trait>>where S: 'async_trait + BlockStore, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
impl<T> Eq for Link<T>where T: Clone,
Auto Trait Implementations§
impl<T> RefUnwindSafe for Link<T>where T: RefUnwindSafe,
impl<T> Send for Link<T>where T: Send,
impl<T> Sync for Link<T>where T: Sync,
impl<T> Unpin for Link<T>where T: Unpin,
impl<T> UnwindSafe for Link<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> Base64Encode for Twhere
T: DagJson,
impl<T> Base64Encode for Twhere T: DagJson,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more