[][src]Struct iprs::multihash::Multihash

pub struct Multihash { /* fields omitted */ }

Type adapts several hashing algorithms within multihash specification.

Implementations

impl Multihash[src]

pub fn new(codec: Multicodec, data: &[u8]) -> Result<Multihash>[src]

Create a Multihash instance, of type multi-codec for data. Digest will be created for data, using the multi-hash algorithm specified by codec.

pub fn from_digest(codec: Multicodec, digest: &[u8]) -> Result<Multihash>[src]

New multihash from digest and multihash-type.

pub fn decode_lazy(data: &[u8]) -> Result<Multihash>[src]

Create a lazy instance of multihash from data, where data contains encoded multihash. Call Self::parse method to de-serialize.

pub fn parse(&mut self) -> Result<()>[src]

Lazy parse. Typically called after creating this instance using Self::decode_lazy constructor.

pub fn decode(buf: &[u8]) -> Result<(Multihash, &[u8])>[src]

Decode a hash-digest that was encoded using multi-format specification.

  • The type is an unsigned variable integer identifying the hash function. There is a default table, and it is configurable. The default table is the [multicodec table].
  • The length is an unsigned variable integer counting the length of the digest, in bytes.
  • The value is the hash function digest, with a length of exactly <digest-length> bytes.

Return the Multihash value and remaining byte-slice. Caller can use Self::to_codec, Self::to_digest, Self::unwrap methods to get the hash-digest and hash-algorithm used to generate the digest.

pub fn encode(&self) -> Result<Vec<u8>>[src]

Encode hash-digest and associated headers as per multi-hash specification.

<hash-func-type><digest-length><digest-value>

impl Multihash[src]

pub fn to_codec(&self) -> Result<Multicodec>[src]

Return the multihash codec.

pub fn to_digest(&self) -> Result<Vec<u8>>[src]

Return the underlying hash digest.

Panic if digest is not generated or decoded.

pub fn unwrap(self) -> Result<(Multicodec, Vec<u8>)>[src]

Unwrap the underlying codec and hash digest. Panic if digest is not generated or decoded.

Trait Implementations

impl Clone for Multihash[src]

impl Display for Multihash[src]

impl Eq for Multihash[src]

impl From<Multihash> for PeerId[src]

impl From<PeerId> for Multihash[src]

impl PartialEq<Multihash> for Multihash[src]

impl StructuralEq for Multihash[src]

impl StructuralPartialEq for Multihash[src]

impl Write for Multihash[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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.

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.

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