Skip to content

Commit fc20e95

Browse files
author
luozijun
committed
impl Debug for all sockaddr types
1 parent 2f09d4c commit fc20e95

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/ifaddrs.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! of interfaces and their associated addresses.
55
66
use std::ffi;
7-
use std::fmt;
87
use std::iter::Iterator;
98
use std::mem;
109
use std::option::Option;
@@ -16,7 +15,7 @@ use sys::socket::SockAddr;
1615
use net::if_::*;
1716

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

35-
impl fmt::Debug for InterfaceAddress {
36-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37-
write!(f, "InterfaceAddress ({:?})", self.interface_name)
38-
}
39-
}
40-
4134
cfg_if! {
4235
if #[cfg(any(target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] {
4336
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {

src/sys/socket/addr.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ impl fmt::Display for InetAddr {
357357
}
358358
}
359359

360+
impl fmt::Debug for InetAddr {
361+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
362+
fmt::Display::fmt(self, f)
363+
}
364+
}
365+
360366
/*
361367
*
362368
* ===== IpAddr =====
@@ -409,6 +415,12 @@ impl fmt::Display for IpAddr {
409415
}
410416
}
411417

418+
impl fmt::Debug for IpAddr {
419+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
420+
fmt::Display::fmt(self, f)
421+
}
422+
}
423+
412424
/*
413425
*
414426
* ===== Ipv4Addr =====
@@ -470,6 +482,12 @@ impl fmt::Display for Ipv4Addr {
470482
}
471483
}
472484

485+
impl fmt::Debug for Ipv4Addr {
486+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
487+
fmt::Display::fmt(self, f)
488+
}
489+
}
490+
473491
/*
474492
*
475493
* ===== Ipv6Addr =====
@@ -524,6 +542,12 @@ impl fmt::Display for Ipv6Addr {
524542
}
525543
}
526544

545+
impl fmt::Debug for Ipv6Addr {
546+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
547+
fmt::Display::fmt(self, f)
548+
}
549+
}
550+
527551
/*
528552
*
529553
* ===== UnixAddr =====
@@ -658,6 +682,12 @@ impl fmt::Display for UnixAddr {
658682
}
659683
}
660684

685+
impl fmt::Debug for UnixAddr {
686+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
687+
fmt::Display::fmt(self, f)
688+
}
689+
}
690+
661691
/*
662692
*
663693
* ===== Sock addr =====
@@ -850,6 +880,12 @@ pub mod netlink {
850880
write!(f, "pid: {} groups: {}", self.pid(), self.groups())
851881
}
852882
}
883+
884+
impl fmt::Debug for NetlinkAddr {
885+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
886+
fmt::Display::fmt(self, f)
887+
}
888+
}
853889
}
854890

855891
#[cfg(any(target_os = "ios", target_os = "macos"))]
@@ -948,4 +984,10 @@ pub mod sys_control {
948984
write!(f, "id: {} unit: {}", self.id(), self.unit())
949985
}
950986
}
987+
988+
impl fmt::Debug for SysControlAddr {
989+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
990+
fmt::Display::fmt(self, f)
991+
}
992+
}
951993
}

0 commit comments

Comments
 (0)