Skip to content

Commit 0e6b034

Browse files
author
luozijun
committed
impl Debug for all sockaddr types
1 parent 5d50aca commit 0e6b034

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
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: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ impl fmt::Display for InetAddr {
363363
}
364364
}
365365

366+
impl fmt::Debug for InetAddr {
367+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
368+
fmt::Display::fmt(self, f)
369+
}
370+
}
371+
366372
/*
367373
*
368374
* ===== IpAddr =====
@@ -415,6 +421,12 @@ impl fmt::Display for IpAddr {
415421
}
416422
}
417423

424+
impl fmt::Debug for IpAddr {
425+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
426+
fmt::Display::fmt(self, f)
427+
}
428+
}
429+
418430
/*
419431
*
420432
* ===== Ipv4Addr =====
@@ -482,6 +494,12 @@ impl fmt::Display for Ipv4Addr {
482494
}
483495
}
484496

497+
impl fmt::Debug for Ipv4Addr {
498+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
499+
fmt::Display::fmt(self, f)
500+
}
501+
}
502+
485503
/*
486504
*
487505
* ===== Ipv6Addr =====
@@ -536,6 +554,12 @@ impl fmt::Display for Ipv6Addr {
536554
}
537555
}
538556

557+
impl fmt::Debug for Ipv6Addr {
558+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
559+
fmt::Display::fmt(self, f)
560+
}
561+
}
562+
539563
/*
540564
*
541565
* ===== UnixAddr =====
@@ -676,14 +700,20 @@ impl fmt::Display for UnixAddr {
676700
}
677701
}
678702

703+
impl fmt::Debug for UnixAddr {
704+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
705+
fmt::Display::fmt(self, f)
706+
}
707+
}
708+
679709
/*
680710
*
681711
* ===== Sock addr =====
682712
*
683713
*/
684714

685715
/// Represents a socket address
686-
#[derive(Copy)]
716+
#[derive(Copy, Debug)]
687717
pub enum SockAddr {
688718
Inet(InetAddr),
689719
Unix(UnixAddr),
@@ -875,6 +905,12 @@ pub mod netlink {
875905
write!(f, "pid: {} groups: {}", self.pid(), self.groups())
876906
}
877907
}
908+
909+
impl fmt::Debug for NetlinkAddr {
910+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
911+
fmt::Display::fmt(self, f)
912+
}
913+
}
878914
}
879915

880916
#[cfg(any(target_os = "ios", target_os = "macos"))]
@@ -973,4 +1009,10 @@ pub mod sys_control {
9731009
write!(f, "id: {} unit: {}", self.id(), self.unit())
9741010
}
9751011
}
1012+
1013+
impl fmt::Debug for SysControlAddr {
1014+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1015+
fmt::Display::fmt(self, f)
1016+
}
1017+
}
9761018
}

0 commit comments

Comments
 (0)