summaryrefslogtreecommitdiff
path: root/src/sys/socket
diff options
context:
space:
mode:
authorBryant Mairs <bryant@mai.rs>2019-03-10 08:29:23 -0700
committerBryant Mairs <bryant@mai.rs>2019-06-09 11:31:46 -0700
commitc50e987b4e169e2d7dc7089c91407e1e55c550f1 (patch)
tree4892e791f8809dfa1501e9fa4ff999a106a8dd04 /src/sys/socket
parent2075ac70bdd4848b08213a237feb32f5506096e0 (diff)
downloadnix-c50e987b4e169e2d7dc7089c91407e1e55c550f1.zip
Add extra traits for all types
Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all traits are supported by all types, which is why many are missing some.
Diffstat (limited to 'src/sys/socket')
-rw-r--r--src/sys/socket/addr.rs364
-rw-r--r--src/sys/socket/mod.rs75
-rw-r--r--src/sys/socket/sockopt.rs6
3 files changed, 40 insertions, 405 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index fc24bd79..c6988227 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -2,8 +2,9 @@ use super::sa_family_t;
use {Error, Result, NixPath};
use errno::Errno;
use libc;
-use std::{fmt, hash, mem, net, ptr, slice};
+use std::{fmt, mem, net, ptr, slice};
use std::ffi::OsStr;
+use std::hash::{Hash, Hasher};
use std::path::Path;
use std::os::unix::ffi::OsStrExt;
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -245,7 +246,7 @@ impl AddressFamily {
}
}
-#[derive(Copy)]
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum InetAddr {
V4(libc::sockaddr_in),
V6(libc::sockaddr_in6),
@@ -331,52 +332,6 @@ impl InetAddr {
}
}
-impl PartialEq for InetAddr {
- fn eq(&self, other: &InetAddr) -> bool {
- match (*self, *other) {
- (InetAddr::V4(ref a), InetAddr::V4(ref b)) => {
- a.sin_port == b.sin_port &&
- a.sin_addr.s_addr == b.sin_addr.s_addr
- }
- (InetAddr::V6(ref a), InetAddr::V6(ref b)) => {
- a.sin6_port == b.sin6_port &&
- a.sin6_addr.s6_addr == b.sin6_addr.s6_addr &&
- a.sin6_flowinfo == b.sin6_flowinfo &&
- a.sin6_scope_id == b.sin6_scope_id
- }
- _ => false,
- }
- }
-}
-
-impl Eq for InetAddr {
-}
-
-impl hash::Hash for InetAddr {
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- match *self {
- InetAddr::V4(ref a) => {
- ( a.sin_family,
- a.sin_port,
- a.sin_addr.s_addr ).hash(s)
- }
- InetAddr::V6(ref a) => {
- ( a.sin6_family,
- a.sin6_port,
- &a.sin6_addr.s6_addr,
- a.sin6_flowinfo,
- a.sin6_scope_id ).hash(s)
- }
- }
- }
-}
-
-impl Clone for InetAddr {
- fn clone(&self) -> InetAddr {
- *self
- }
-}
-
impl fmt::Display for InetAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
@@ -386,18 +341,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 =====
*
*/
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum IpAddr {
V4(Ipv4Addr),
V6(Ipv6Addr),
@@ -442,19 +391,13 @@ 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 =====
*
*/
-#[derive(Copy)]
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Ipv4Addr(pub libc::in_addr);
impl Ipv4Addr {
@@ -487,28 +430,6 @@ impl Ipv4Addr {
}
}
-impl PartialEq for Ipv4Addr {
- fn eq(&self, other: &Ipv4Addr) -> bool {
- self.0.s_addr == other.0.s_addr
- }
-}
-
-impl Eq for Ipv4Addr {
-}
-
-impl hash::Hash for Ipv4Addr {
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- let saddr = self.0.s_addr;
- saddr.hash(s)
- }
-}
-
-impl Clone for Ipv4Addr {
- fn clone(&self) -> Ipv4Addr {
- *self
- }
-}
-
impl fmt::Display for Ipv4Addr {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let octets = self.octets();
@@ -516,19 +437,13 @@ 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 =====
*
*/
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Ipv6Addr(pub libc::in6_addr);
// Note that IPv6 addresses are stored in big endian order on all architectures.
@@ -576,18 +491,6 @@ 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 =====
- *
- */
-
/// A wrapper around `sockaddr_un`.
///
/// This also tracks the length of `sun_path` address (excluding
@@ -596,7 +499,7 @@ impl fmt::Debug for Ipv6Addr {
/// does not require that `sun_len` include the terminating null even for normal
/// sockets. Note that the actual sockaddr length is greater by
/// `offset_of!(libc::sockaddr_un, sun_path)`
-#[derive(Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct UnixAddr(pub libc::sockaddr_un, pub usize);
impl UnixAddr {
@@ -688,27 +591,6 @@ impl UnixAddr {
}
}
-impl PartialEq for UnixAddr {
- fn eq(&self, other: &UnixAddr) -> bool {
- self.sun_path() == other.sun_path()
- }
-}
-
-impl Eq for UnixAddr {
-}
-
-impl hash::Hash for UnixAddr {
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- ( self.0.sun_family, self.sun_path() ).hash(s)
- }
-}
-
-impl Clone for UnixAddr {
- fn clone(&self) -> UnixAddr {
- *self
- }
-}
-
impl fmt::Display for UnixAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.1 == 0 {
@@ -722,20 +604,22 @@ impl fmt::Display for UnixAddr {
}
}
-impl fmt::Debug for UnixAddr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- fmt::Display::fmt(self, f)
+impl PartialEq for UnixAddr {
+ fn eq(&self, other: &UnixAddr) -> bool {
+ self.sun_path() == other.sun_path()
}
}
-/*
- *
- * ===== Sock addr =====
- *
- */
+impl Eq for UnixAddr {}
+
+impl Hash for UnixAddr {
+ fn hash<H: Hasher>(&self, s: &mut H) {
+ ( self.0.sun_family, self.sun_path() ).hash(s)
+ }
+}
/// Represents a socket address
-#[derive(Copy, Debug)]
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum SockAddr {
Inet(InetAddr),
Unix(UnixAddr),
@@ -883,68 +767,6 @@ impl SockAddr {
}
}
-impl PartialEq for SockAddr {
- fn eq(&self, other: &SockAddr) -> bool {
- match (*self, *other) {
- (SockAddr::Inet(ref a), SockAddr::Inet(ref b)) => {
- a == b
- }
- (SockAddr::Unix(ref a), SockAddr::Unix(ref b)) => {
- a == b
- }
- #[cfg(any(target_os = "android", target_os = "linux"))]
- (SockAddr::Netlink(ref a), SockAddr::Netlink(ref b)) => {
- a == b
- }
- #[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "linux",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
- (SockAddr::Link(ref a), SockAddr::Link(ref b)) => {
- a == b
- }
- _ => false,
- }
- }
-}
-
-impl Eq for SockAddr {
-}
-
-impl hash::Hash for SockAddr {
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- match *self {
- SockAddr::Inet(ref a) => a.hash(s),
- SockAddr::Unix(ref a) => a.hash(s),
- #[cfg(any(target_os = "android", target_os = "linux"))]
- SockAddr::Netlink(ref a) => a.hash(s),
- #[cfg(any(target_os = "android", target_os = "linux"))]
- SockAddr::Alg(ref a) => a.hash(s),
- #[cfg(any(target_os = "ios", target_os = "macos"))]
- SockAddr::SysControl(ref a) => a.hash(s),
- #[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "linux",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
- SockAddr::Link(ref ether_addr) => ether_addr.hash(s)
- }
- }
-}
-
-impl Clone for SockAddr {
- fn clone(&self) -> SockAddr {
- *self
- }
-}
-
impl fmt::Display for SockAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
@@ -974,30 +796,10 @@ pub mod netlink {
use ::sys::socket::addr::AddressFamily;
use libc::{sa_family_t, sockaddr_nl};
use std::{fmt, mem};
- use std::hash::{Hash, Hasher};
- #[derive(Copy, Clone)]
+ #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub struct NetlinkAddr(pub sockaddr_nl);
- // , PartialEq, Eq, Debug, Hash
- impl PartialEq for NetlinkAddr {
- fn eq(&self, other: &Self) -> bool {
- let (inner, other) = (self.0, other.0);
- (inner.nl_family, inner.nl_pid, inner.nl_groups) ==
- (other.nl_family, other.nl_pid, other.nl_groups)
- }
- }
-
- impl Eq for NetlinkAddr {}
-
- impl Hash for NetlinkAddr {
- fn hash<H: Hasher>(&self, s: &mut H) {
- let inner = self.0;
- (inner.nl_family, inner.nl_pid, inner.nl_groups).hash(s);
- }
- }
-
-
impl NetlinkAddr {
pub fn new(pid: u32, groups: u32) -> NetlinkAddr {
let mut addr: sockaddr_nl = unsafe { mem::zeroed() };
@@ -1022,12 +824,6 @@ 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 = "android", target_os = "linux"))]
@@ -1098,11 +894,13 @@ pub mod sys_control {
use ::sys::socket::addr::AddressFamily;
use libc::{self, c_uchar};
use std::{fmt, mem};
- use std::hash::{Hash, Hasher};
use std::os::unix::io::RawFd;
use {Errno, Error, Result};
+ // FIXME: Move type into `libc`
#[repr(C)]
+ #[derive(Clone, Copy)]
+ #[allow(missing_debug_implementations)]
pub struct ctl_ioc_info {
pub ctl_id: u32,
pub ctl_name: [c_uchar; MAX_KCTL_NAME],
@@ -1114,28 +912,10 @@ pub mod sys_control {
ioctl_readwrite!(ctl_info, CTL_IOC_MAGIC, CTL_IOC_INFO, ctl_ioc_info);
- #[derive(Copy, Clone)]
#[repr(C)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct SysControlAddr(pub libc::sockaddr_ctl);
- impl PartialEq for SysControlAddr {
- fn eq(&self, other: &Self) -> bool {
- let (inner, other) = (self.0, other.0);
- (inner.sc_id, inner.sc_unit) ==
- (other.sc_id, other.sc_unit)
- }
- }
-
- impl Eq for SysControlAddr {}
-
- impl Hash for SysControlAddr {
- fn hash<H: Hasher>(&self, s: &mut H) {
- let inner = self.0;
- (inner.sc_id, inner.sc_unit).hash(s);
- }
- }
-
-
impl SysControlAddr {
pub fn new(id: u32, unit: u32) -> SysControlAddr {
let addr = libc::sockaddr_ctl {
@@ -1178,27 +958,15 @@ pub mod sys_control {
fmt::Debug::fmt(self, f)
}
}
-
- impl fmt::Debug for SysControlAddr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.debug_struct("SysControlAddr")
- .field("sc_len", &self.0.sc_len)
- .field("sc_family", &self.0.sc_family)
- .field("ss_sysaddr", &self.0.ss_sysaddr)
- .field("sc_id", &self.0.sc_id)
- .field("sc_unit", &self.0.sc_unit)
- .finish()
- }
- }
}
#[cfg(any(target_os = "android", target_os = "linux"))]
mod datalink {
- use super::{libc, hash, fmt, AddressFamily};
+ use super::{libc, fmt, AddressFamily};
/// Hardware Address
- #[derive(Clone, Copy)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct LinkAddr(pub libc::sockaddr_ll);
impl LinkAddr {
@@ -1246,26 +1014,6 @@ mod datalink {
}
}
- impl Eq for LinkAddr {}
-
- impl PartialEq for LinkAddr {
- fn eq(&self, other: &Self) -> bool {
- let (a, b) = (self.0, other.0);
- (a.sll_family, a.sll_protocol, a.sll_ifindex, a.sll_hatype,
- a.sll_pkttype, a.sll_halen, a.sll_addr) ==
- (b.sll_family, b.sll_protocol, b.sll_ifindex, b.sll_hatype,
- b.sll_pkttype, b.sll_halen, b.sll_addr)
- }
- }
-
- impl hash::Hash for LinkAddr {
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- let a = self.0;
- (a.sll_family, a.sll_protocol, a.sll_ifindex, a.sll_hatype,
- a.sll_pkttype, a.sll_halen, a.sll_addr).hash(s);
- }
- }
-
impl fmt::Display for LinkAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let addr = self.addr();
@@ -1278,12 +1026,6 @@ mod datalink {
addr[5])
}
}
-
- impl fmt::Debug for LinkAddr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- fmt::Display::fmt(self, f)
- }
- }
}
#[cfg(any(target_os = "dragonfly",
@@ -1293,10 +1035,10 @@ mod datalink {
target_os = "netbsd",
target_os = "openbsd"))]
mod datalink {
- use super::{libc, hash, fmt, AddressFamily};
+ use super::{libc, fmt, AddressFamily};
/// Hardware Address
- #[derive(Clone, Copy)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct LinkAddr(pub libc::sockaddr_dl);
impl LinkAddr {
@@ -1368,52 +1110,6 @@ mod datalink {
}
}
- impl Eq for LinkAddr {}
-
- impl PartialEq for LinkAddr {
- #[cfg(any(target_os = "freebsd",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
- fn eq(&self, other: &Self) -> bool {
- let (a, b) = (self.0, other.0);
- (a.sdl_len, a.sdl_family, a.sdl_index, a.sdl_type,
- a.sdl_nlen, a.sdl_alen, a.sdl_slen, &a.sdl_data[..]) ==
- (b.sdl_len, b.sdl_family, b.sdl_index, b.sdl_type,
- b.sdl_nlen, b.sdl_alen, b.sdl_slen, &b.sdl_data[..])
- }
-
- #[cfg(target_os = "dragonfly")]
- fn eq(&self, other: &Self) -> bool {
- let (a, b) = (self.0, other.0);
- (a.sdl_len, a.sdl_family, a.sdl_index, a.sdl_type, a.sdl_nlen,
- a.sdl_alen, a.sdl_slen, a.sdl_data, a.sdl_rcf, a.sdl_route) ==
- (b.sdl_len, b.sdl_family, b.sdl_index, b.sdl_type, b.sdl_nlen,
- b.sdl_alen, b.sdl_slen, b.sdl_data, b.sdl_rcf, b.sdl_route)
- }
- }
-
- impl hash::Hash for LinkAddr {
- #[cfg(any(target_os = "freebsd",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- let a = self.0;
- (a.sdl_len, a.sdl_family, a.sdl_index, a.sdl_type,
- a.sdl_nlen, a.sdl_alen, a.sdl_slen, &a.sdl_data[..]).hash(s);
- }
-
- #[cfg(target_os = "dragonfly")]
- fn hash<H: hash::Hasher>(&self, s: &mut H) {
- let a = self.0;
- (a.sdl_len, a.sdl_family, a.sdl_index, a.sdl_type, a.sdl_nlen,
- a.sdl_alen, a.sdl_slen, a.sdl_data, a.sdl_rcf, a.sdl_route).hash(s);
- }
- }
-
impl fmt::Display for LinkAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let addr = self.addr();
@@ -1426,12 +1122,6 @@ mod datalink {
addr[5])
}
}
-
- impl fmt::Debug for LinkAddr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- fmt::Display::fmt(self, f)
- }
- }
}
#[cfg(test)]
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index a8631f24..0e27216f 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -5,7 +5,7 @@ use {Error, Result};
use errno::Errno;
use libc::{self, c_void, c_int, iovec, socklen_t, size_t,
CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_LEN};
-use std::{fmt, mem, ptr, slice};
+use std::{mem, ptr, slice};
use std::os::unix::io::RawFd;
use sys::time::TimeVal;
use sys::uio::IoVec;
@@ -189,7 +189,7 @@ cfg_if! {
///
/// This struct is used with the `SO_PEERCRED` ancillary message for UNIX sockets.
#[repr(C)]
- #[derive(Clone, Copy)]
+ #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UnixCredentials(libc::ucred);
impl UnixCredentials {
@@ -209,13 +209,6 @@ cfg_if! {
}
}
- impl PartialEq for UnixCredentials {
- fn eq(&self, other: &Self) -> bool {
- self.0.pid == other.0.pid && self.0.uid == other.0.uid && self.0.gid == other.0.gid
- }
- }
- impl Eq for UnixCredentials {}
-
impl From<libc::ucred> for UnixCredentials {
fn from(cred: libc::ucred) -> Self {
UnixCredentials(cred)
@@ -227,16 +220,6 @@ cfg_if! {
self.0
}
}
-
- impl fmt::Debug for UnixCredentials {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.debug_struct("UnixCredentials")
- .field("pid", &self.0.pid)
- .field("uid", &self.0.uid)
- .field("gid", &self.0.gid)
- .finish()
- }
- }
}
}
@@ -244,7 +227,7 @@ cfg_if! {
///
/// This is a wrapper type around `ip_mreq`.
#[repr(C)]
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct IpMembershipRequest(libc::ip_mreq);
impl IpMembershipRequest {
@@ -259,32 +242,11 @@ impl IpMembershipRequest {
}
}
-impl PartialEq for IpMembershipRequest {
- fn eq(&self, other: &Self) -> bool {
- self.0.imr_multiaddr.s_addr == other.0.imr_multiaddr.s_addr
- && self.0.imr_interface.s_addr == other.0.imr_interface.s_addr
- }
-}
-impl Eq for IpMembershipRequest {}
-
-impl fmt::Debug for IpMembershipRequest {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mref = &self.0.imr_multiaddr;
- let maddr = mref.s_addr;
- let iref = &self.0.imr_interface;
- let ifaddr = iref.s_addr;
- f.debug_struct("IpMembershipRequest")
- .field("imr_multiaddr", &maddr)
- .field("imr_interface", &ifaddr)
- .finish()
- }
-}
-
/// Request for ipv6 multicast socket operations
///
/// This is a wrapper type around `ipv6_mreq`.
#[repr(C)]
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Ipv6MembershipRequest(libc::ipv6_mreq);
impl Ipv6MembershipRequest {
@@ -297,23 +259,6 @@ impl Ipv6MembershipRequest {
}
}
-impl PartialEq for Ipv6MembershipRequest {
- fn eq(&self, other: &Self) -> bool {
- self.0.ipv6mr_multiaddr.s6_addr == other.0.ipv6mr_multiaddr.s6_addr &&
- self.0.ipv6mr_interface == other.0.ipv6mr_interface
- }
-}
-impl Eq for Ipv6MembershipRequest {}
-
-impl fmt::Debug for Ipv6MembershipRequest {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.debug_struct("Ipv6MembershipRequest")
- .field("ipv6mr_multiaddr", &self.0.ipv6mr_multiaddr.s6_addr)
- .field("ipv6mr_interface", &self.0.ipv6mr_interface)
- .finish()
- }
-}
-
cfg_if! {
// Darwin and DragonFly BSD always align struct cmsghdr to 32-bit only.
if #[cfg(any(target_os = "dragonfly", target_os = "ios", target_os = "macos"))] {
@@ -386,7 +331,7 @@ macro_rules! cmsg_space {
/// let cmsg: CmsgSpace<([RawFd; 3], CmsgSpace<[RawFd; 2]>)> = CmsgSpace::new();
/// ```
#[repr(C)]
-#[allow(missing_debug_implementations)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CmsgSpace<T> {
_hdr: cmsghdr,
_pad: [align_of_cmsg_data; 0],
@@ -419,7 +364,7 @@ impl CmsgBuffer for Vec<u8> {
}
}
-#[allow(missing_debug_implementations)] // msghdr isn't Debug
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RecvMsg<'a> {
pub bytes: usize,
cmsghdr: Option<&'a cmsghdr>,
@@ -439,7 +384,7 @@ impl<'a> RecvMsg<'a> {
}
}
-#[allow(missing_debug_implementations)] // msghdr isn't Debug
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CmsgIterator<'a> {
/// Control message buffer to decode from. Must adhere to cmsg alignment.
cmsghdr: Option<&'a cmsghdr>,
@@ -478,7 +423,7 @@ impl<'a> Iterator for CmsgIterator<'a> {
// alignment issues.
//
// See https://github.com/nix-rust/nix/issues/999
-#[allow(missing_debug_implementations)]
+#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ControlMessageOwned {
/// Received version of
/// [`ControlMessage::ScmRights`][#enum.ControlMessage.html#variant.ScmRights]
@@ -679,7 +624,7 @@ impl ControlMessageOwned {
/// exhaustively pattern-match it.
///
/// [Further reading](http://man7.org/linux/man-pages/man3/cmsg.3.html)
-#[allow(missing_debug_implementations)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ControlMessage<'a> {
/// A message of type `SCM_RIGHTS`, containing an array of file
/// descriptors passed between processes.
@@ -742,7 +687,7 @@ pub enum ControlMessage<'a> {
// An opaque structure used to prevent cmsghdr from being a public type
#[doc(hidden)]
-#[allow(missing_debug_implementations)]
+#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UnknownCmsg(cmsghdr, Vec<u8>);
impl<'a> ControlMessage<'a> {
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index 5f19e5f3..a9960100 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -173,7 +173,7 @@ macro_rules! sockopt_impl {
};
(GetOnly, $name:ident, $level:path, $flag:path, $ty:ty, $getter:ty) => {
- #[derive(Copy, Clone, Debug)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct $name;
getsockopt_impl!($name, $level, $flag, $ty, $getter);
@@ -184,14 +184,14 @@ macro_rules! sockopt_impl {
};
(SetOnly, $name:ident, $level:path, $flag:path, $ty:ty, $setter:ty) => {
- #[derive(Copy, Clone, Debug)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct $name;
setsockopt_impl!($name, $level, $flag, $ty, $setter);
};
(Both, $name:ident, $level:path, $flag:path, $ty:ty, $getter:ty, $setter:ty) => {
- #[derive(Copy, Clone, Debug)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct $name;
setsockopt_impl!($name, $level, $flag, $ty, $setter);