Struct libipld::block::Block [−][src]
pub struct Block<S> { /* fields omitted */ }Expand description
Block
Implementations
impl<S: StoreParams> Block<S>[src]
impl<S: StoreParams> Block<S>[src]pub fn new(cid: Cid, data: Vec<u8>) -> Result<Self>[src]
pub fn new(cid: Cid, data: Vec<u8>) -> Result<Self>[src]Creates a new block. Returns an error if the hash doesn’t match the data.
pub fn new_unchecked(cid: Cid, data: Vec<u8>) -> Self[src]
pub fn new_unchecked(cid: Cid, data: Vec<u8>) -> Self[src]Creates a new block without verifying the cid.
pub fn encode<CE: Codec, T: Encode<CE> + ?Sized>(
codec: CE,
hcode: S::Hashes,
payload: &T
) -> Result<Self> where
CE: Into<S::Codecs>, [src]
pub fn encode<CE: Codec, T: Encode<CE> + ?Sized>(
codec: CE,
hcode: S::Hashes,
payload: &T
) -> Result<Self> where
CE: Into<S::Codecs>, [src]Encode a block.`
pub fn decode<CD: Codec, T: Decode<CD>>(&self) -> Result<T> where
S::Codecs: Into<CD>, [src]
pub fn decode<CD: Codec, T: Decode<CD>>(&self) -> Result<T> where
S::Codecs: Into<CD>, [src]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()));
pub fn references<E: Extend<Cid>>(&self, set: &mut E) -> Result<()> where
Ipld: References<S::Codecs>, [src]
pub fn references<E: Extend<Cid>>(&self, set: &mut E) -> Result<()> where
Ipld: References<S::Codecs>, [src]Returns the references.
Methods from Deref<Target = Cid>
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
impl<S> AsRef<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]
impl<S> AsRef<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]impl<S> Borrow<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]
impl<S> Borrow<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]impl<S> Eq for Block<S>[src]
Auto Trait Implementations
impl<S> RefUnwindSafe for Block<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<S> Send for Block<S> where
S: Send,
S: Send,
impl<S> Sync for Block<S> where
S: Sync,
S: Sync,
impl<S> Unpin for Block<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for Block<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> References<RawCodec> for T[src]
impl<T> References<RawCodec> for T[src]impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more