mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-23 23:01:33 +00:00
Add some TryFrom implementations (#1060)
This commit is contained in:
@ -22,7 +22,7 @@ use crate::PublicKey;
|
||||
use bs58;
|
||||
use quick_error::quick_error;
|
||||
use multihash;
|
||||
use std::{fmt, str::FromStr};
|
||||
use std::{convert::TryFrom, fmt, str::FromStr};
|
||||
|
||||
/// Identifier of a peer of the network.
|
||||
///
|
||||
@ -143,6 +143,22 @@ impl From<PublicKey> for PeerId {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for PeerId {
|
||||
type Error = Vec<u8>;
|
||||
|
||||
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
PeerId::from_bytes(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<multihash::Multihash> for PeerId {
|
||||
type Error = multihash::Multihash;
|
||||
|
||||
fn try_from(value: multihash::Multihash) -> Result<Self, Self::Error> {
|
||||
PeerId::from_multihash(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<multihash::Multihash> for PeerId {
|
||||
#[inline]
|
||||
fn eq(&self, other: &multihash::Multihash) -> bool {
|
||||
|
Reference in New Issue
Block a user