Add From<IpAddr> for Multiaddr (#623)

This commit is contained in:
Pierre Krieger
2018-11-12 10:44:18 +01:00
committed by Toralf Wittner
parent a3b0914d73
commit 6a7c722ffc

View File

@@ -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 {