mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-23 14:51:34 +00:00
Add some TryFrom implementations (#1060)
This commit is contained in:
@ -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> {
|
||||
|
Reference in New Issue
Block a user