Skip to content

Commit ef40c9c

Browse files
committed
Derive and implement a few traits for InterfaceAddress and its iterator.
1 parent 8fc62a8 commit ef40c9c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/ifaddrs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! of interfaces and their associated addresses.
55
66
use std::ffi;
7+
use std::fmt;
78
use std::iter::Iterator;
89
use std::mem;
910
use std::option::Option;
@@ -15,6 +16,7 @@ use sys::socket::SockAddr;
1516
use net::if_::*;
1617

1718
/// Describes a single address for an interface as returned by `getifaddrs`.
19+
#[derive(Clone, Eq, Hash, PartialEq)]
1820
pub struct InterfaceAddress {
1921
/// Name of the network interface
2022
pub interface_name: String,
@@ -30,6 +32,12 @@ pub struct InterfaceAddress {
3032
pub destination: Option<SockAddr>,
3133
}
3234

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+
3341
cfg_if! {
3442
if #[cfg(any(target_os = "emscripten", target_os = "fuchsia", target_os="linux"))] {
3543
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {
@@ -73,6 +81,7 @@ impl InterfaceAddress {
7381
/// Use the function `getifaddrs` to create this Iterator. Note that the
7482
/// actual list of interfaces can be iterated once and will be freed as
7583
/// soon as the Iterator goes out of scope.
84+
#[derive(Debug, Eq, Hash, PartialEq)]
7685
pub struct InterfaceAddressIterator {
7786
base: *mut libc::ifaddrs,
7887
next: *mut libc::ifaddrs,

0 commit comments

Comments
 (0)