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<(), Error>where
W: Write,
pub fn write_bytes<W>(&self, w: W) -> Result<(), Error>where W: Write,
Writes the bytes to a byte stream.
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 + PartialEq,
impl<T> PartialEq<Link<T>> for Link<T>where T: Clone + PartialEq,
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 more