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 15, 2017
1 parent 291d618 commit 4e7a6ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 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
44 changes: 43 additions & 1 deletion src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,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 @@ -415,6 +421,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 @@ -482,6 +494,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 @@ -536,6 +554,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 @@ -676,14 +700,20 @@ 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 =====
*
*/

/// Represents a socket address
#[derive(Copy)]
#[derive(Copy, Debug)]
pub enum SockAddr {
Inet(InetAddr),
Unix(UnixAddr),
Expand Down Expand Up @@ -875,6 +905,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 @@ -973,4 +1009,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 4e7a6ec

Please sign in to comment.