Add conversions to/from std wire types
parent
96fd18ff8f
commit
a9fc8c225b
|
@ -160,6 +160,16 @@ impl Address {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", feature = "proto-ipv4", feature = "proto-ipv6"))]
|
||||
impl From<::std::net::IpAddr> for Address {
|
||||
fn from(x: ::std::net::IpAddr) -> Address {
|
||||
match x {
|
||||
::std::net::IpAddr::V4(ipv4) => Address::Ipv4(ipv4.into()),
|
||||
::std::net::IpAddr::V6(ipv6) => Address::Ipv6(ipv6.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Address {
|
||||
fn default() -> Address {
|
||||
Address::Unspecified
|
||||
|
@ -325,6 +335,16 @@ impl Endpoint {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", feature = "proto-ipv4", feature = "proto-ipv6"))]
|
||||
impl From<::std::net::SocketAddr> for Endpoint {
|
||||
fn from(x: ::std::net::SocketAddr) -> Endpoint {
|
||||
Endpoint {
|
||||
addr: x.ip().into(),
|
||||
port: x.port(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Endpoint {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}:{}", self.addr, self.port)
|
||||
|
|
|
@ -85,6 +85,20 @@ impl Address {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl From<::std::net::Ipv4Addr> for Address {
|
||||
fn from(x: ::std::net::Ipv4Addr) -> Address {
|
||||
Address(x.octets())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl From<Address> for ::std::net::Ipv4Addr {
|
||||
fn from(Address(x): Address) -> ::std::net::Ipv4Addr {
|
||||
x.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Address {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let bytes = self.0;
|
||||
|
|
|
@ -171,6 +171,20 @@ impl Address {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl From<::std::net::Ipv6Addr> for Address {
|
||||
fn from(x: ::std::net::Ipv6Addr) -> Address {
|
||||
Address(x.octets())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl From<Address> for ::std::net::Ipv6Addr {
|
||||
fn from(Address(x): Address) -> ::std::net::Ipv6Addr {
|
||||
x.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Address {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.is_ipv4_mapped() {
|
||||
|
|
Loading…
Reference in New Issue