mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-08-01 01:11:58 +00:00
Add From<IpAddr> for Multiaddr (#623)
This commit is contained in:
committed by
Toralf Wittner
parent
a3b0914d73
commit
6a7c722ffc
@@ -7,7 +7,7 @@ use std::{
|
||||
convert::From,
|
||||
fmt,
|
||||
io::{Cursor, Write},
|
||||
net::{Ipv4Addr, Ipv6Addr},
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr},
|
||||
str::{self, FromStr}
|
||||
};
|
||||
use unsigned_varint::{encode, decode};
|
||||
@@ -383,6 +383,16 @@ impl<'a> fmt::Display for Protocol<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<IpAddr> for Protocol<'a> {
|
||||
#[inline]
|
||||
fn from(addr: IpAddr) -> Self {
|
||||
match addr {
|
||||
IpAddr::V4(addr) => Protocol::Ip4(addr),
|
||||
IpAddr::V6(addr) => Protocol::Ip6(addr),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Ipv4Addr> for Protocol<'a> {
|
||||
#[inline]
|
||||
fn from(addr: Ipv4Addr) -> Self {
|
||||
|
Reference in New Issue
Block a user