[][src]Struct multihash::MultihashRefGeneric

pub struct MultihashRefGeneric<'a, T> { /* fields omitted */ }

Represents a valid multihash.

Implementations

impl<'a, T: TryFrom<u64>> MultihashRefGeneric<'a, T>[src]

pub fn from_slice(input: &'a [u8]) -> Result<Self, DecodeError>[src]

Creates a new MultihashRef from a &[u8]. If the input data is not a valid multihash an error is returned.

Example

use multihash::{MultihashRef, Sha2_256};

let mh = Sha2_256::digest(b"hello world");

// valid multihash
let mh2 = MultihashRef::from_slice(&mh).unwrap();

// invalid multihash
assert!(MultihashRef::from_slice(&vec![1, 2, 3]).is_err());

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

Returns the algorithm used in this multihash.

Example

use multihash::{Code, MultihashRef, Sha2_256};

let mh = Sha2_256::digest(b"hello world");

// valid multihash
let mh2 = MultihashRef::from_slice(&mh).unwrap();
assert_eq!(mh2.algorithm(), Code::Sha2_256);

pub fn digest(&self) -> &'a [u8][src]

Returns the hash digest.

Example

use multihash::{wrap, Code, Multihash, Sha2_256};

let mh = Sha2_256::digest(b"hello world");
let digest = mh.digest();
let wrapped: Multihash = wrap(Code::Sha2_256, &digest);
assert_eq!(wrapped.digest(), digest);

pub fn to_owned(&self) -> MultihashGeneric<T>[src]

Builds a Multihash that owns the data.

This operation allocates.

pub fn as_bytes(&self) -> &'a [u8][src]

Returns the bytes representation of this multihash.

Trait Implementations

impl<'a, T: Clone> Clone for MultihashRefGeneric<'a, T>[src]

impl<'a, T: Copy> Copy for MultihashRefGeneric<'a, T>[src]

impl<'a, T: Debug> Debug for MultihashRefGeneric<'a, T>[src]

impl<'a, T: TryFrom<u64>> Deref for MultihashRefGeneric<'a, T>[src]

type Target = [u8]

The resulting type after dereferencing.

impl<'a, T: Eq> Eq for MultihashRefGeneric<'a, T>[src]

impl<'a, T: Hash> Hash for MultihashRefGeneric<'a, T>[src]

impl<'a, T: TryFrom<u64>> Into<Vec<u8>> for MultihashRefGeneric<'a, T>[src]

impl<'a, T: Ord> Ord for MultihashRefGeneric<'a, T>[src]

impl<'a, T: TryFrom<u64>> PartialEq<MultihashGeneric<T>> for MultihashRefGeneric<'a, T>[src]

impl<'a, T: TryFrom<u64>> PartialEq<MultihashRefGeneric<'a, T>> for MultihashGeneric<T>[src]

impl<'a, T: PartialEq> PartialEq<MultihashRefGeneric<'a, T>> for MultihashRefGeneric<'a, T>[src]

impl<'a, T: PartialOrd> PartialOrd<MultihashRefGeneric<'a, T>> for MultihashRefGeneric<'a, T>[src]

impl<'a, T> StructuralEq for MultihashRefGeneric<'a, T>[src]

impl<'a, T> StructuralPartialEq for MultihashRefGeneric<'a, T>[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for MultihashRefGeneric<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for MultihashRefGeneric<'a, T> where
    T: Send

impl<'a, T> Sync for MultihashRefGeneric<'a, T> where
    T: Sync

impl<'a, T> Unpin for MultihashRefGeneric<'a, T> where
    T: Unpin

impl<'a, T> UnwindSafe for MultihashRefGeneric<'a, T> where
    T: UnwindSafe

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, 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.