Struct ipfs_embed::Block [−][src]
pub struct Block<S> { /* fields omitted */ }
Expand description
Block
Implementations
Creates a new block. Returns an error if the hash doesn’t match the data.
Creates a new block without verifying the cid.
Returns the cid.
Returns the inner cid and data.
Encode a block.`
Decodes a block.
Example
Decoding to [Ipld
]:
use libipld::block::Block; use libipld::cbor::DagCborCodec; use libipld::ipld::Ipld; use libipld::multihash::Code; use libipld::store::DefaultParams; let block = Block::<DefaultParams>::encode(DagCborCodec, Code::Blake3_256, "Hello World!").unwrap(); let ipld = block.decode::<DagCborCodec, Ipld>().unwrap(); assert_eq!(ipld, Ipld::String("Hello World!".to_string()));
Returns the decoded ipld.
pub fn references<E>(&self, set: &mut E) -> Result<(), Error> where
E: Extend<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>,
Ipld: References<<S as StoreParams>::Codecs>,
pub fn references<E>(&self, set: &mut E) -> Result<(), Error> where
E: Extend<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>,
Ipld: References<<S as StoreParams>::Codecs>,
Returns the references.
Methods from Deref<Target = Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>
pub fn version(&self) -> Version
pub fn version(&self) -> Version
Returns the cid version.
pub fn hash(&self) -> &Multihash<S>
pub fn hash(&self) -> &Multihash<S>
Returns the cid multihash.
pub 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.
pub 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
Auto Trait Implementations
impl<S> RefUnwindSafe for Block<S> where
S: RefUnwindSafe,
impl<S> UnwindSafe for Block<S> where
S: UnwindSafe,
Blanket Implementations
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
pub fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
pub fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Mutably borrows from an owned value. Read more
impl<T> CallHasher for T where
T: Hash,
impl<T> CallHasher for T where
T: Hash,
pub fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
pub fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn protocol_name(&self) -> &[u8]
pub fn protocol_name(&self) -> &[u8]
The protocol name as bytes. Transmitted on the network. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V