From cd1e16d1afb70ed510565c52d053b40a9f7c6975 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Mon, 21 Jan 2019 19:49:48 -0800 Subject: [PATCH] Implement Hash for all types --- README.md | 5 +- src/macros.rs | 2 +- src/unix/bsd/apple/b32.rs | 7 ++ src/unix/bsd/apple/b64.rs | 7 ++ src/unix/bsd/apple/mod.rs | 98 +++++++++++++++++++++++ src/unix/bsd/mod.rs | 18 +++++ src/unix/notbsd/android/b64/mod.rs | 25 ++++++ src/unix/notbsd/android/mod.rs | 54 +++++++++++++ src/unix/notbsd/linux/mod.rs | 38 +++++++++ src/unix/notbsd/linux/musl/b32/x86.rs | 11 +++ src/unix/notbsd/linux/musl/b64/x86_64.rs | 11 +++ src/unix/notbsd/linux/musl/mod.rs | 19 +++++ src/unix/notbsd/linux/other/b32/x86.rs | 29 +++++++ src/unix/notbsd/linux/other/b64/x86_64.rs | 26 ++++++ src/unix/notbsd/linux/other/mod.rs | 16 ++++ src/unix/notbsd/linux/s390x.rs | 6 ++ src/unix/notbsd/mod.rs | 25 ++++++ 17 files changed, 394 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4885cc9e..1caab854 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,9 @@ libc = { version = "0.2", features = ["align"] } ``` All structs implemented by the libc crate have the `Copy` and `Clone` traits -implemented for them. The additional traits of `Debug, `Eq`, and `PartialEq` -can be enabled with the *extra_traits* feature (requires Rust 1.25 or newer): +implemented for them. The additional traits of `Debug, `Eq`, `Hash`, and +`PartialEq` can be enabled with the *extra_traits* feature (requires Rust 1.25 +or newer): ```toml [dependencies] diff --git a/src/macros.rs b/src/macros.rs index 3877797c..aabe6e8e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -39,7 +39,7 @@ macro_rules! s { __item! { #[repr(C)] $(#[$attr])* - #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, PartialEq))] + #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] pub $t $i { $($field)* } } impl ::dox::Copy for $i {} diff --git a/src/unix/bsd/apple/b32.rs b/src/unix/bsd/apple/b32.rs index 4950c197..284eae39 100644 --- a/src/unix/bsd/apple/b32.rs +++ b/src/unix/bsd/apple/b32.rs @@ -73,6 +73,13 @@ impl std::fmt::Debug for pthread_attr_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_attr_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } +} pub const __PTHREAD_MUTEX_SIZE__: usize = 40; pub const __PTHREAD_COND_SIZE__: usize = 24; diff --git a/src/unix/bsd/apple/b64.rs b/src/unix/bsd/apple/b64.rs index c5f00384..2161fc47 100644 --- a/src/unix/bsd/apple/b64.rs +++ b/src/unix/bsd/apple/b64.rs @@ -78,6 +78,13 @@ impl std::fmt::Debug for pthread_attr_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_attr_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } +} pub const __PTHREAD_MUTEX_SIZE__: usize = 56; pub const __PTHREAD_COND_SIZE__: usize = 40; diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 16ce25f0..08995917 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -608,6 +608,12 @@ impl std::fmt::Debug for semun { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for semun { + fn hash(&self, state: &mut H) { + unsafe { self.val.hash(state) }; + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for proc_threadinfo { fn eq(&self, other: &proc_threadinfo) -> bool { self.pth_user_time == other.pth_user_time @@ -648,6 +654,22 @@ impl std::fmt::Debug for proc_threadinfo { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for proc_threadinfo { + fn hash(&self, state: &mut H) { + self.pth_user_time.hash(state); + self.pth_system_time.hash(state); + self.pth_cpu_usage.hash(state); + self.pth_policy.hash(state); + self.pth_run_state.hash(state); + self.pth_flags.hash(state); + self.pth_sleep_time.hash(state); + self.pth_curpri.hash(state); + self.pth_priority.hash(state); + self.pth_maxpriority.hash(state); + self.pth_name.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for statfs { fn eq(&self, other: &statfs) -> bool { self.f_bsize == other.f_bsize @@ -702,6 +724,27 @@ impl std::fmt::Debug for statfs { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for statfs { + fn hash(&self, state: &mut H) { + self.f_bsize.hash(state); + self.f_iosize.hash(state); + self.f_blocks.hash(state); + self.f_bfree.hash(state); + self.f_bavail.hash(state); + self.f_files.hash(state); + self.f_ffree.hash(state); + self.f_fsid.hash(state); + self.f_owner.hash(state); + self.f_flags.hash(state); + self.f_fssubtype.hash(state); + self.f_fstypename.hash(state); + self.f_type.hash(state); + self.f_mntonname.hash(state); + self.f_mntfromname.hash(state); + self.f_reserved.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for dirent { fn eq(&self, other: &dirent) -> bool { self.d_ino == other.d_ino @@ -732,6 +775,17 @@ impl std::fmt::Debug for dirent { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for dirent { + fn hash(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_seekoff.hash(state); + self.d_reclen.hash(state); + self.d_namlen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for pthread_rwlock_t { fn eq(&self, other: &pthread_rwlock_t) -> bool { self.__sig == other.__sig @@ -754,6 +808,13 @@ impl std::fmt::Debug for pthread_rwlock_t { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_rwlock_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for pthread_mutex_t { fn eq(&self, other: &pthread_mutex_t) -> bool { self.__sig == other.__sig @@ -776,6 +837,13 @@ impl std::fmt::Debug for pthread_mutex_t { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_mutex_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for pthread_cond_t { fn eq(&self, other: &pthread_cond_t) -> bool { self.__sig == other.__sig @@ -798,6 +866,13 @@ impl std::fmt::Debug for pthread_cond_t { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_cond_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for sockaddr_storage { fn eq(&self, other: &sockaddr_storage) -> bool { self.ss_len == other.ss_len @@ -830,6 +905,16 @@ impl std::fmt::Debug for sockaddr_storage { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for sockaddr_storage { + fn hash(&self, state: &mut H) { + self.ss_len.hash(state); + self.ss_family.hash(state); + self.__ss_pad1.hash(state); + self.__ss_align.hash(state); + self.__ss_pad2.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for utmpx { fn eq(&self, other: &utmpx) -> bool { self.ut_user @@ -866,6 +951,19 @@ impl std::fmt::Debug for utmpx { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for utmpx { + fn hash(&self, state: &mut H) { + self.ut_user.hash(state); + self.ut_id.hash(state); + self.ut_line.hash(state); + self.ut_pid.hash(state); + self.ut_type.hash(state); + self.ut_tv.hash(state); + self.ut_host.hash(state); + self.ut_pad.hash(state); + } +} pub const _UTX_USERSIZE: usize = 256; pub const _UTX_LINESIZE: usize = 32; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 74bbaf75..0541c5a0 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -162,6 +162,14 @@ impl std::fmt::Debug for sockaddr_un { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for sockaddr_un { + fn hash(&self, state: &mut H) { + self.sun_len.hash(state); + self.sun_family.hash(state); + self.sun_path.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for utsname { fn eq(&self, other: &utsname) -> bool { self.sysname @@ -204,6 +212,16 @@ impl std::fmt::Debug for utsname { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for utsname { + fn hash(&self, state: &mut H) { + self.sysname.hash(state); + self.nodename.hash(state); + self.release.hash(state); + self.version.hash(state); + self.machine.hash(state); + } +} pub const LC_ALL: ::c_int = 0; pub const LC_COLLATE: ::c_int = 1; diff --git a/src/unix/notbsd/android/b64/mod.rs b/src/unix/notbsd/android/b64/mod.rs index c5a6a79e..1da667bc 100644 --- a/src/unix/notbsd/android/b64/mod.rs +++ b/src/unix/notbsd/android/b64/mod.rs @@ -150,6 +150,13 @@ impl std::fmt::Debug for pthread_mutex_t { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_mutex_t { + fn hash(&self, state: &mut H) { + self.value.hash(state); + self.__reserved.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for pthread_cond_t { fn eq(&self, other: &pthread_cond_t) -> bool { self.value == other.value @@ -172,6 +179,13 @@ impl std::fmt::Debug for pthread_cond_t { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_cond_t { + fn hash(&self, state: &mut H) { + self.value.hash(state); + self.__reserved.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for pthread_rwlock_t { fn eq(&self, other: &pthread_rwlock_t) -> bool { self.numLocks == other.numLocks @@ -201,6 +215,17 @@ impl std::fmt::Debug for pthread_rwlock_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_rwlock_t { + fn hash(&self, state: &mut H) { + self.numLocks.hash(state); + self.writerThreadId.hash(state); + self.pendingReaders.hash(state); + self.pendingWriters.hash(state); + self.attr.hash(state); + self.__reserved.hash(state); + } +} pub const RTLD_GLOBAL: ::c_int = 0x00100; pub const RTLD_NOW: ::c_int = 2; diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 99faaef6..de4ff593 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -269,6 +269,16 @@ impl std::fmt::Debug for dirent { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for dirent { + fn hash(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for dirent64 { fn eq(&self, other: &dirent64) -> bool { self.d_ino == other.d_ino @@ -297,6 +307,16 @@ impl std::fmt::Debug for dirent64 { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for dirent64 { + fn hash(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for siginfo_t { fn eq(&self, other: &siginfo_t) -> bool { self.si_signo == other.si_signo @@ -321,6 +341,16 @@ impl std::fmt::Debug for siginfo_t { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for siginfo_t { + fn hash(&self, state: &mut H) { + self.si_signo.hash(state); + self.si_errno.hash(state); + self.si_code.hash(state); + // Ignore _pad + // Ignore _align + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for lastlog { fn eq(&self, other: &lastlog) -> bool { self.ll_time == other.ll_time @@ -349,6 +379,14 @@ impl std::fmt::Debug for lastlog { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for lastlog { + fn hash(&self, state: &mut H) { + self.ll_time.hash(state); + self.ll_line.hash(state); + self.ll_host.hash(state); + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for utmp { fn eq(&self, other: &utmp) -> bool { self.ut_type == other.ut_type @@ -396,6 +434,22 @@ impl std::fmt::Debug for utmp { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for utmp { + fn hash(&self, state: &mut H) { + self.ut_type.hash(state); + self.ut_pid.hash(state); + self.ut_line.hash(state); + self.ut_id.hash(state); + self.ut_user.hash(state); + self.ut_host.hash(state); + self.ut_exit.hash(state); + self.ut_session.hash(state); + self.ut_tv.hash(state); + self.ut_addr_v6.hash(state); + self.unused.hash(state); + } +} pub const O_TRUNC: ::c_int = 512; pub const O_CLOEXEC: ::c_int = 0x80000; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index b0eac45b..31fc3792 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -687,6 +687,16 @@ impl std::fmt::Debug for dirent { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for dirent { + fn hash(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } +} #[cfg(feature = "extra_traits")] impl PartialEq for dirent64 { @@ -716,6 +726,16 @@ impl std::fmt::Debug for dirent64 { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for dirent64 { + fn hash(&self, state: &mut H) { + self.d_ino.hash(state); + self.d_off.hash(state); + self.d_reclen.hash(state); + self.d_type.hash(state); + self.d_name.hash(state); + } +} #[cfg(feature = "extra_traits")] impl PartialEq for pthread_cond_t { @@ -733,6 +753,12 @@ impl std::fmt::Debug for pthread_cond_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_cond_t { + fn hash(&self, state: &mut H) { + self.size.hash(state); + } +} #[cfg(feature = "extra_traits")] impl PartialEq for pthread_mutex_t { @@ -750,6 +776,12 @@ impl std::fmt::Debug for pthread_mutex_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_mutex_t { + fn hash(&self, state: &mut H) { + self.size.hash(state); + } +} #[cfg(feature = "extra_traits")] impl PartialEq for pthread_rwlock_t { @@ -767,6 +799,12 @@ impl std::fmt::Debug for pthread_rwlock_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for pthread_rwlock_t { + fn hash(&self, state: &mut H) { + self.size.hash(state); + } +} pub const ABDAY_1: ::nl_item = 0x20000; pub const ABDAY_2: ::nl_item = 0x20001; diff --git a/src/unix/notbsd/linux/musl/b32/x86.rs b/src/unix/notbsd/linux/musl/b32/x86.rs index 9b79356f..42ff2a28 100644 --- a/src/unix/notbsd/linux/musl/b32/x86.rs +++ b/src/unix/notbsd/linux/musl/b32/x86.rs @@ -207,6 +207,17 @@ impl std::fmt::Debug for ucontext_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for ucontext_t { + fn hash(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + self.__private.hash(state); + } +} pub const SIGSTKSZ: ::size_t = 8192; pub const MINSIGSTKSZ: ::size_t = 2048; diff --git a/src/unix/notbsd/linux/musl/b64/x86_64.rs b/src/unix/notbsd/linux/musl/b64/x86_64.rs index 1679a3ab..8462a4f6 100644 --- a/src/unix/notbsd/linux/musl/b64/x86_64.rs +++ b/src/unix/notbsd/linux/musl/b64/x86_64.rs @@ -105,6 +105,17 @@ impl std::fmt::Debug for ucontext_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for ucontext_t { + fn hash(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + self.__private.hash(state); + } +} // Syscall table diff --git a/src/unix/notbsd/linux/musl/mod.rs b/src/unix/notbsd/linux/musl/mod.rs index 6d1a0a13..b3ab6502 100644 --- a/src/unix/notbsd/linux/musl/mod.rs +++ b/src/unix/notbsd/linux/musl/mod.rs @@ -141,6 +141,25 @@ impl std::fmt::Debug for sysinfo { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for sysinfo { + fn hash(&self, state: &mut H) { + self.uptime.hash(state); + self.loads.hash(state); + self.totalram.hash(state); + self.freeram.hash(state); + self.sharedram.hash(state); + self.bufferram.hash(state); + self.totalswap.hash(state); + self.freeswap.hash(state); + self.procs.hash(state); + self.pad.hash(state); + self.totalhigh.hash(state); + self.freehigh.hash(state); + self.mem_unit.hash(state); + self.__reserved.hash(state); + } +} pub const SFD_CLOEXEC: ::c_int = 0x080000; diff --git a/src/unix/notbsd/linux/other/b32/x86.rs b/src/unix/notbsd/linux/other/b32/x86.rs index d3186c0f..fb489821 100644 --- a/src/unix/notbsd/linux/other/b32/x86.rs +++ b/src/unix/notbsd/linux/other/b32/x86.rs @@ -256,6 +256,24 @@ impl std::fmt::Debug for user_fpxregs_struct { } } #[cfg(feature = "extra_traits")] +impl std::hash::Hash for user_fpxregs_struct { + fn hash(&self, state: &mut H) { + self.cwd.hash(state); + self.swd.hash(state); + self.twd.hash(state); + self.fop.hash(state); + self.fip.hash(state); + self.fcs.hash(state); + self.foo.hash(state); + self.fos.hash(state); + self.mxcsr.hash(state); + // Ignore __reserved field + self.st_space.hash(state); + self.xmm_space.hash(state); + // Ignore padding field + } +} +#[cfg(feature = "extra_traits")] impl PartialEq for ucontext_t { fn eq(&self, other: &ucontext_t) -> bool { self.uc_flags == other.uc_flags @@ -281,6 +299,17 @@ impl std::fmt::Debug for ucontext_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for ucontext_t { + fn hash(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + // Ignore __private field + } +} pub const O_DIRECT: ::c_int = 0x4000; pub const O_DIRECTORY: ::c_int = 0x10000; diff --git a/src/unix/notbsd/linux/other/b64/x86_64.rs b/src/unix/notbsd/linux/other/b64/x86_64.rs index 02745b90..b2a67ee9 100644 --- a/src/unix/notbsd/linux/other/b64/x86_64.rs +++ b/src/unix/notbsd/linux/other/b64/x86_64.rs @@ -273,6 +273,21 @@ impl std::fmt::Debug for user_fpregs_struct { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for user_fpregs_struct { + fn hash(&self, state: &mut H) { + self.cwd.hash(state); + self.ftw.hash(state); + self.fop.hash(state); + self.rip.hash(state); + self.rdp.hash(state); + self.mxcsr.hash(state); + self.mxcr_mask.hash(state); + self.st_space.hash(state); + self.xmm_space.hash(state); + // Ignore padding field + } +} #[cfg(feature = "extra_traits")] impl PartialEq for ucontext_t { @@ -300,6 +315,17 @@ impl std::fmt::Debug for ucontext_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for ucontext_t { + fn hash(&self, state: &mut H) { + self.uc_flags.hash(state); + self.uc_link.hash(state); + self.uc_stack.hash(state); + self.uc_mcontext.hash(state); + self.uc_sigmask.hash(state); + // Ignore __private field + } +} pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs index fa0e39ba..4036ceab 100644 --- a/src/unix/notbsd/linux/other/mod.rs +++ b/src/unix/notbsd/linux/other/mod.rs @@ -286,6 +286,22 @@ impl std::fmt::Debug for utmpx { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for utmpx { + fn hash(&self, state: &mut H) { + self.ut_type.hash(state); + self.ut_pid.hash(state); + self.ut_line.hash(state); + self.ut_id.hash(state); + self.ut_user.hash(state); + self.ut_host.hash(state); + self.ut_exit.hash(state); + self.ut_session.hash(state); + self.ut_tv.hash(state); + self.ut_addr_v6.hash(state); + self.__glibc_reserved.hash(state); + } +} pub const __UT_LINESIZE: usize = 32; pub const __UT_NAMESIZE: usize = 32; diff --git a/src/unix/notbsd/linux/s390x.rs b/src/unix/notbsd/linux/s390x.rs index 8a6b88a8..f53e47e0 100644 --- a/src/unix/notbsd/linux/s390x.rs +++ b/src/unix/notbsd/linux/s390x.rs @@ -352,6 +352,12 @@ impl std::fmt::Debug for fpreg_t { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for fpreg_t { + fn hash(&self, state: &mut H) { + self.d.to_bits().hash(state); + } +} pub const SFD_CLOEXEC: ::c_int = 0x080000; diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index cd613d44..4b06e6e6 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -254,6 +254,13 @@ impl std::fmt::Debug for sockaddr_un { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for sockaddr_un { + fn hash(&self, state: &mut H) { + self.sun_family.hash(state); + self.sun_path.hash(state); + } +} #[cfg(feature = "extra_traits")] impl PartialEq for sockaddr_storage { @@ -278,6 +285,13 @@ impl std::fmt::Debug for sockaddr_storage { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for sockaddr_storage { + fn hash(&self, state: &mut H) { + self.ss_family.hash(state); + self.__ss_pad2.hash(state); + } +} #[cfg(feature = "extra_traits")] impl PartialEq for utsname { @@ -328,6 +342,17 @@ impl std::fmt::Debug for utsname { .finish() } } +#[cfg(feature = "extra_traits")] +impl std::hash::Hash for utsname { + fn hash(&self, state: &mut H) { + self.sysname.hash(state); + self.nodename.hash(state); + self.release.hash(state); + self.version.hash(state); + self.machine.hash(state); + self.domainname.hash(state); + } +} // intentionally not public, only used for fd_set cfg_if! {