Struct ipfs_embed::Block
source · [−]pub struct Block<S> { /* private fields */ }
Expand description
Block
Implementations
sourceimpl<S> Block<S>where
S: StoreParams,
impl<S> Block<S>where
S: StoreParams,
sourcepub fn new(cid: Cid<64>, data: Vec<u8, Global>) -> Result<Block<S>, Error>
pub fn new(cid: Cid<64>, data: Vec<u8, Global>) -> Result<Block<S>, Error>
Creates a new block. Returns an error if the hash doesn’t match the data.
sourcepub fn new_unchecked(cid: Cid<64>, data: Vec<u8, Global>) -> Block<S>
pub fn new_unchecked(cid: Cid<64>, data: Vec<u8, Global>) -> Block<S>
Creates a new block without verifying the cid.
sourcepub fn data(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn data(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Returns the payload.
sourcepub fn into_inner(self) -> (Cid<64>, Vec<u8, Global>)
pub fn into_inner(self) -> (Cid<64>, Vec<u8, Global>)
Returns the inner cid and data.
sourcepub fn encode<CE, T>(
codec: CE,
hcode: <S as StoreParams>::Hashes,
payload: &T
) -> Result<Block<S>, Error>where
CE: Codec + Into<<S as StoreParams>::Codecs>,
T: Encode<CE> + ?Sized,
pub fn encode<CE, T>(
codec: CE,
hcode: <S as StoreParams>::Hashes,
payload: &T
) -> Result<Block<S>, Error>where
CE: Codec + Into<<S as StoreParams>::Codecs>,
T: Encode<CE> + ?Sized,
Encode a block.`
sourcepub fn decode<CD, T>(&self) -> Result<T, Error>where
CD: Codec,
T: Decode<CD>,
<S as StoreParams>::Codecs: Into<CD>,
pub fn decode<CD, T>(&self) -> Result<T, Error>where
CD: Codec,
T: Decode<CD>,
<S as StoreParams>::Codecs: Into<CD>,
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()));
sourcepub fn ipld(&self) -> Result<Ipld, Error>where
Ipld: Decode<<S as StoreParams>::Codecs>,
pub fn ipld(&self) -> Result<Ipld, Error>where
Ipld: Decode<<S as StoreParams>::Codecs>,
Returns the decoded ipld.
sourcepub fn references<E>(&self, set: &mut E) -> Result<(), Error>where
E: Extend<Cid<64>>,
Ipld: References<<S as StoreParams>::Codecs>,
pub fn references<E>(&self, set: &mut E) -> Result<(), Error>where
E: Extend<Cid<64>>,
Ipld: References<<S as StoreParams>::Codecs>,
Returns the references.
Methods from Deref<Target = Cid<64>>
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_bytes(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn to_bytes(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Returns the encoded bytes of the Cid
.
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> Eq for Block<S>
Auto Trait Implementations
impl<S> RefUnwindSafe for Block<S>where
S: RefUnwindSafe,
impl<S> Send for Block<S>where
S: Send,
impl<S> Sync for Block<S>where
S: Sync,
impl<S> Unpin for Block<S>where
S: Unpin,
impl<S> UnwindSafe for Block<S>where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere
T: AsRef<[u8]>,
sourcefn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self
into the result. Lower case
letters are used (e.g. f9b4ca
) Read moresourcefn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self
into the result. Upper case
letters are used (e.g. F9B4CA
) Read more