Struct libipld::block::Block

source ·
pub struct Block<S> { /* private fields */ }
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 payload.

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.

Returns the references.

Methods from Deref<Target = Cid>§

Returns the cid version.

Returns the cid codec.

Returns the cid multihash.

Writes the bytes to a byte stream, returns the number of bytes written.

Returns the length in bytes needed to encode this cid into bytes.

Returns the encoded bytes of the Cid.

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§

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Scrape the references from an impl Read. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.