[][src]Trait tiny_multihash::MultihashDigest

pub trait MultihashDigest: Clone + Debug + Eq + Send + Sync + 'static {
    fn new(code: u64, input: &[u8]) -> Result<Self, Error>;
fn wrap(code: u64, digest: &[u8]) -> Result<Self, Error>;
fn code(&self) -> u64;
fn size(&self) -> u8;
fn digest(&self) -> &[u8];
fn read<R: Read>(r: R) -> Result<Self, Error>
    where
        Self: Sized
; fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
    where
        Self: Sized
, { ... }
fn write<W: Write>(&self, w: W) -> Result<(), Error> { ... }
fn to_bytes(&self) -> Vec<u8> { ... }
fn to_raw(&self) -> Result<RawMultihash, Error> { ... } }

Trait for reading and writhing Multihashes.

It is usually derived from a list of hashers by the Multihash derive.

Required methods

fn new(code: u64, input: &[u8]) -> Result<Self, Error>

Returns the hash of the input.

fn wrap(code: u64, digest: &[u8]) -> Result<Self, Error>

Wraps the digest in a multihash.

fn code(&self) -> u64

Returns the code of the multihash.

fn size(&self) -> u8

Returns the actual size of the digest, that will be returned by digest().

fn digest(&self) -> &[u8]

Returns the digest.

fn read<R: Read>(r: R) -> Result<Self, Error> where
    Self: Sized

Reads a multihash from a byte stream.

Loading content...

Provided methods

fn from_bytes(bytes: &[u8]) -> Result<Self, Error> where
    Self: Sized

Parses a multihash from a bytes.

You need to make sure the passed in bytes have the correct length. The digest length needs to match the size value of the multihash.

fn write<W: Write>(&self, w: W) -> Result<(), Error>

Writes a multihash to a byte stream.

fn to_bytes(&self) -> Vec<u8>

Returns the bytes of a multihash.

fn to_raw(&self) -> Result<RawMultihash, Error>

Returns the RawMultihash.

Loading content...

Implementors

impl MultihashDigest for Multihash[src]

Loading content...