Struct ipfs_embed::Block[][src]

pub struct Block<S> { /* fields omitted */ }
Expand description

Block

Implementations

impl<S> Block<S> where
    S: StoreParams
[src]

pub fn new(
    cid: Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>,
    data: Vec<u8, Global>
) -> Result<Block<S>, Error>
[src]

Creates a new block. Returns an error if the hash doesn’t match the data.

pub fn new_unchecked(
    cid: Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>,
    data: Vec<u8, Global>
) -> Block<S>
[src]

Creates a new block without verifying the cid.

pub fn cid(
    &self
) -> &Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
[src]

Returns the cid.

pub fn data(&self) -> &[u8][src]

Returns the payload.

pub fn into_inner(
    self
) -> (Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>, Vec<u8, Global>)
[src]

Returns the inner cid and data.

pub fn encode<CE, T>(
    codec: CE,
    hcode: <S as StoreParams>::Hashes,
    payload: &T
) -> Result<Block<S>, Error> where
    T: Encode<CE> + ?Sized,
    CE: Codec + Into<<S as StoreParams>::Codecs>, 
[src]

Encode a block.`

pub fn decode<CD, T>(&self) -> Result<T, Error> where
    T: Decode<CD>,
    CD: Codec,
    <S as StoreParams>::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 ipld(&self) -> Result<Ipld, Error> where
    Ipld: Decode<<S as StoreParams>::Codecs>, 
[src]

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>, 
[src]

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

Returns the cid version.

pub fn codec(&self) -> u64

Returns the cid codec.

pub fn hash(&self) -> &Multihash<S>

Returns the cid multihash.

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>

Returns the encoded bytes of the Cid.

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<[u8]> for Block<S>[src]

pub fn as_ref(&self) -> &[u8][src]

Performs the conversion.

impl<S> AsRef<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]

pub fn as_ref(
    &self
) -> &Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
[src]

Performs the conversion.

impl<S> Borrow<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]

pub fn borrow(
    &self
) -> &Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
[src]

Immutably borrows from an owned value. Read more

impl<S> Clone for Block<S> where
    S: Clone
[src]

pub fn clone(&self) -> Block<S>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<S> Debug for Block<S>[src]

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]

Formats the value using the given formatter. Read more

impl<S> Deref for Block<S>[src]

type Target = Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>

The resulting type after dereferencing.

pub fn deref(&self) -> &<Block<S> as Deref>::Target[src]

Dereferences the value.

impl<S> Hash for Block<S>[src]

pub fn hash<SH>(&self, hasher: &mut SH) where
    SH: Hasher
[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<S> PartialEq<Block<S>> for Block<S>[src]

pub fn eq(&self, other: &Block<S>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<S> Eq for Block<S>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> CallHasher for T where
    T: Hash

pub fn get_hash<H>(&self, hasher: H) -> u64 where
    H: Hasher

impl<T> CallHasher for T where
    T: Hash + ?Sized

pub default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64 where
    B: BuildHasher,
    H: Hash + ?Sized

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ProtocolName for T where
    T: AsRef<[u8]>, 

pub fn protocol_name(&self) -> &[u8]

The protocol name as bytes. Transmitted on the network. Read more

impl<T> References<RawCodec> for T

pub fn references<R, E>(
    _c: RawCodec,
    _r: &mut R,
    _set: &mut E
) -> Result<(), Error> where
    E: Extend<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>,
    R: Read

Scrape the references from an impl Read. Read more

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToHex for T where
    T: AsRef<[u8]>, 
[src]

pub fn encode_hex<U>(&self) -> U where
    U: FromIterator<char>, 
[src]

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca) Read more

pub fn encode_hex_upper<U>(&self) -> U where
    U: FromIterator<char>, 
[src]

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA) Read more

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V