Add some TryFrom implementations (#1060)

This commit is contained in:
Pierre Krieger
2019-04-17 14:16:50 +02:00
committed by GitHub
parent 3ec9c37e17
commit a4173705db
2 changed files with 26 additions and 2 deletions

View File

@ -9,7 +9,7 @@ mod errors;
mod hashes;
use sha2::Digest;
use std::fmt::Write;
use std::{convert::TryFrom, fmt::Write};
use unsigned_varint::{decode, encode};
pub use self::errors::{DecodeError, DecodeOwnedError, EncodeError};
@ -165,6 +165,14 @@ impl<'a> PartialEq<MultihashRef<'a>> for Multihash {
}
}
impl TryFrom<Vec<u8>> for Multihash {
type Error = DecodeOwnedError;
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
Multihash::from_bytes(value)
}
}
/// Represents a valid multihash.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct MultihashRef<'a> {