Skip to content

Commit

Permalink
impl Debug for all sockaddr types
Browse files Browse the repository at this point in the history
  • Loading branch information
luozijun committed Dec 27, 2017
1 parent 2f09d4c commit fc20e95
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/ifaddrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! of interfaces and their associated addresses.
use std::ffi;
use std::fmt;
use std::iter::Iterator;
use std::mem;
use std::option::Option;
Expand All @@ -16,7 +15,7 @@ use sys::socket::SockAddr;
use net::if_::*;

/// Describes a single address for an interface as returned by `getifaddrs`.
#[derive(Clone, Eq, Hash, PartialEq)]
#[derive(Clone, Eq, Hash, PartialEq, Debug)]
pub struct InterfaceAddress {
/// Name of the network interface
pub interface_name: String,
Expand All @@ -32,12 +31,6 @@ pub struct InterfaceAddress {
pub destination: Option<SockAddr>,
}

impl fmt::Debug for InterfaceAddress {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "InterfaceAddress ({:?})", self.interface_name)
}
}

cfg_if! {
if #[cfg(any(target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] {
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {
Expand Down
42 changes: 42 additions & 0 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ impl fmt::Display for InetAddr {
}
}

impl fmt::Debug for InetAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}

/*
*
* ===== IpAddr =====
Expand Down Expand Up @@ -409,6 +415,12 @@ impl fmt::Display for IpAddr {
}
}

impl fmt::Debug for IpAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}

/*
*
* ===== Ipv4Addr =====
Expand Down Expand Up @@ -470,6 +482,12 @@ impl fmt::Display for Ipv4Addr {
}
}

impl fmt::Debug for Ipv4Addr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}

/*
*
* ===== Ipv6Addr =====
Expand Down Expand Up @@ -524,6 +542,12 @@ impl fmt::Display for Ipv6Addr {
}
}

impl fmt::Debug for Ipv6Addr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}

/*
*
* ===== UnixAddr =====
Expand Down Expand Up @@ -658,6 +682,12 @@ impl fmt::Display for UnixAddr {
}
}

impl fmt::Debug for UnixAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}

/*
*
* ===== Sock addr =====
Expand Down Expand Up @@ -850,6 +880,12 @@ pub mod netlink {
write!(f, "pid: {} groups: {}", self.pid(), self.groups())
}
}

impl fmt::Debug for NetlinkAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
}

#[cfg(any(target_os = "ios", target_os = "macos"))]
Expand Down Expand Up @@ -948,4 +984,10 @@ pub mod sys_control {
write!(f, "id: {} unit: {}", self.id(), self.unit())
}
}

impl fmt::Debug for SysControlAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
}

0 comments on commit fc20e95

Please sign in to comment.