Trait otter_api_tests::Hash 1.0.0[−][src]
pub trait Hash { fn hash<H>(&self, state: &mut H)
where
H: Hasher; fn hash_slice<H>(data: &[Self], state: &mut H)
where
H: Hasher, { ... } }
Expand description
A hashable type.
Types implementing Hash
are able to be hash
ed with an instance of
Hasher
.
Implementing Hash
You can derive Hash
with #[derive(Hash)]
if all fields implement Hash
.
The resulting hash will be the combination of the values from calling
hash
on each field.
#[derive(Hash)] struct Rustacean { name: String, country: String, }
If you need more control over how a value is hashed, you can of course
implement the Hash
trait yourself:
use std::hash::{Hash, Hasher}; struct Person { id: u32, name: String, phone: u64, } impl Hash for Person { fn hash<H: Hasher>(&self, state: &mut H) { self.id.hash(state); self.phone.hash(state); } }
Hash
and Eq
When implementing both Hash
and Eq
, it is important that the following
property holds:
k1 == k2 -> hash(k1) == hash(k2)
In other words, if two keys are equal, their hashes must also be equal.
HashMap
and HashSet
both rely on this behavior.
Thankfully, you won’t need to worry about upholding this property when
deriving both Eq
and Hash
with #[derive(PartialEq, Eq, Hash)]
.
Required methods
Provided methods
Feeds a slice of this type into the given Hasher
.
This method is meant as a convenience, but its implementation is
also explicitly left unspecified. It isn’t guaranteed to be
equivalent to repeated calls of hash
and implementations of
Hash
should keep that in mind and call hash
themselves
if the slice isn’t treated as a whole unit in the PartialEq
implementation.
For example, a VecDeque
implementation might naïvely call
as_slices
and then hash_slice
on each slice, but this
is wrong since the two slices can change with a call to
make_contiguous
without affecting the PartialEq
result. Since these slices aren’t treated as singular
units, and instead part of a larger deque, this method cannot
be used.
Examples
use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; let mut hasher = DefaultHasher::new(); let numbers = [6, 28, 496, 8128]; Hash::hash_slice(&numbers, &mut hasher); println!("Hash is {:x}!", hasher.finish());
Implementations on Foreign Types
impl<'data> Hash for SymbolMapName<'data>
impl<'data> Hash for SymbolMapName<'data>
impl<'data> Hash for ObjectMapEntry<'data>
impl<'data> Hash for ObjectMapEntry<'data>
impl<'data> Hash for CompressedData<'data>
impl<'data> Hash for CompressedData<'data>
URLs hash like their serialization.
Case-insensitive hashing
Case-insensitive hashing
Examples
let a: Authority = "HELLO.com".parse().unwrap(); let b: Authority = "hello.coM".parse().unwrap(); let mut s = DefaultHasher::new(); a.hash(&mut s); let a = s.finish(); let mut s = DefaultHasher::new(); b.hash(&mut s); let b = s.finish(); assert_eq!(a, b);
Implementors
impl Hash for WriteStyle
impl Hash for WriteStyle
impl Hash for PosixFadviseAdvice
impl Hash for PosixFadviseAdvice
impl Hash for AioCancelStat
impl Hash for AioCancelStat
impl Hash for AioFsyncMode
impl Hash for AioFsyncMode
impl Hash for MmapAdvise
impl Hash for MmapAdvise
impl Hash for RebootMode
impl Hash for RebootMode
impl Hash for SigHandler
impl Hash for SigHandler
impl Hash for SigevNotify
impl Hash for SigevNotify
impl Hash for SigmaskHow
impl Hash for SigmaskHow
impl Hash for AddressFamily
impl Hash for AddressFamily
impl Hash for SockProtocol
impl Hash for SockProtocol
impl Hash for SpecialCharacterIndices
impl Hash for SpecialCharacterIndices
impl Hash for WaitStatus
impl Hash for WaitStatus
impl Hash for otter_api_tests::shapelib::LittleEndian
impl Hash for otter_api_tests::shapelib::LittleEndian
impl Hash for PathconfVar
impl Hash for PathconfVar
impl Hash for SysconfVar
impl Hash for SysconfVar
NaiveDateTime
can be used as a key to the hash maps (in principle).
Practically this also takes account of fractional seconds, so it is not recommended. (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)
NaiveTime
can be used as a key to the hash maps (in principle).
Practically this also takes account of fractional seconds, so it is not recommended. (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)
impl Hash for Elf32_Chdr
impl Hash for Elf32_Chdr
impl Hash for Elf32_Ehdr
impl Hash for Elf32_Ehdr
impl Hash for Elf32_Phdr
impl Hash for Elf32_Phdr
impl Hash for Elf32_Shdr
impl Hash for Elf32_Shdr
impl Hash for Elf64_Chdr
impl Hash for Elf64_Chdr
impl Hash for Elf64_Ehdr
impl Hash for Elf64_Ehdr
impl Hash for Elf64_Phdr
impl Hash for Elf64_Phdr
impl Hash for Elf64_Shdr
impl Hash for Elf64_Shdr
impl Hash for __c_anonymous_sockaddr_can_j1939
impl Hash for __c_anonymous_sockaddr_can_j1939
impl Hash for __c_anonymous_sockaddr_can_tp
impl Hash for __c_anonymous_sockaddr_can_tp
impl Hash for __exit_status
impl Hash for __exit_status
impl Hash for _libc_fpstate
impl Hash for _libc_fpstate
impl Hash for _libc_fpxreg
impl Hash for _libc_fpxreg
impl Hash for _libc_xmmreg
impl Hash for _libc_xmmreg
impl Hash for arpd_request
impl Hash for arpd_request
impl Hash for arpreq_old
impl Hash for arpreq_old
impl Hash for can_filter
impl Hash for can_filter
impl Hash for dl_phdr_info
impl Hash for dl_phdr_info
impl Hash for epoll_event
impl Hash for epoll_event
impl Hash for fanotify_event_metadata
impl Hash for fanotify_event_metadata
impl Hash for fanotify_response
impl Hash for fanotify_response
impl Hash for ff_condition_effect
impl Hash for ff_condition_effect
impl Hash for ff_constant_effect
impl Hash for ff_constant_effect
impl Hash for ff_envelope
impl Hash for ff_envelope
impl Hash for ff_periodic_effect
impl Hash for ff_periodic_effect
impl Hash for ff_ramp_effect
impl Hash for ff_ramp_effect
impl Hash for ff_rumble_effect
impl Hash for ff_rumble_effect
impl Hash for ff_trigger
impl Hash for ff_trigger
impl Hash for genlmsghdr
impl Hash for genlmsghdr
impl Hash for if_nameindex
impl Hash for if_nameindex
impl Hash for in6_pktinfo
impl Hash for in6_pktinfo
impl Hash for in_pktinfo
impl Hash for in_pktinfo
impl Hash for inotify_event
impl Hash for inotify_event
impl Hash for input_absinfo
impl Hash for input_absinfo
impl Hash for input_event
impl Hash for input_event
impl Hash for input_keymap_entry
impl Hash for input_keymap_entry
impl Hash for input_mask
impl Hash for input_mask
impl Hash for ip_mreq_source
impl Hash for ip_mreq_source
impl Hash for itimerspec
impl Hash for itimerspec
impl Hash for mcontext_t
impl Hash for mcontext_t
impl Hash for nl_mmap_hdr
impl Hash for nl_mmap_hdr
impl Hash for nl_mmap_req
impl Hash for nl_mmap_req
impl Hash for nl_pktinfo
impl Hash for nl_pktinfo
impl Hash for ntptimeval
impl Hash for ntptimeval
impl Hash for packet_mreq
impl Hash for packet_mreq
impl Hash for posix_spawn_file_actions_t
impl Hash for posix_spawn_file_actions_t
impl Hash for posix_spawnattr_t
impl Hash for posix_spawnattr_t
impl Hash for pthread_attr_t
impl Hash for pthread_attr_t
impl Hash for pthread_cond_t
impl Hash for pthread_cond_t
impl Hash for pthread_condattr_t
impl Hash for pthread_condattr_t
impl Hash for pthread_mutex_t
impl Hash for pthread_mutex_t
impl Hash for pthread_mutexattr_t
impl Hash for pthread_mutexattr_t
impl Hash for pthread_rwlock_t
impl Hash for pthread_rwlock_t
impl Hash for pthread_rwlockattr_t
impl Hash for pthread_rwlockattr_t
impl Hash for regmatch_t
impl Hash for regmatch_t
impl Hash for sched_param
impl Hash for sched_param
impl Hash for sock_extended_err
impl Hash for sock_extended_err
impl Hash for sockaddr_alg
impl Hash for sockaddr_alg
impl Hash for sockaddr_ll
impl Hash for sockaddr_ll
impl Hash for sockaddr_nl
impl Hash for sockaddr_nl
impl Hash for sockaddr_vm
impl Hash for sockaddr_vm
impl Hash for statx_timestamp
impl Hash for statx_timestamp
impl Hash for ucontext_t
impl Hash for ucontext_t
impl Hash for uinput_abs_setup
impl Hash for uinput_abs_setup
impl Hash for uinput_ff_erase
impl Hash for uinput_ff_erase
impl Hash for uinput_ff_upload
impl Hash for uinput_ff_upload
impl Hash for uinput_setup
impl Hash for uinput_setup
impl Hash for uinput_user_dev
impl Hash for uinput_user_dev
impl Hash for user_fpregs_struct
impl Hash for user_fpregs_struct
impl Hash for user_regs_struct
impl Hash for user_regs_struct
impl Hash for OwningIter
impl Hash for OwningIter
impl Hash for FallocateFlags
impl Hash for FallocateFlags
impl Hash for SpliceFFlags
impl Hash for SpliceFFlags
impl Hash for InterfaceAddress
impl Hash for InterfaceAddress
impl Hash for InterfaceAddressIterator
impl Hash for InterfaceAddressIterator
impl Hash for DeleteModuleFlags
impl Hash for DeleteModuleFlags
impl Hash for ModuleInitFlags
impl Hash for ModuleInitFlags
impl Hash for InterfaceFlags
impl Hash for InterfaceFlags
impl Hash for OpenptyResult
impl Hash for OpenptyResult
impl Hash for CloneFlags
impl Hash for CloneFlags
impl Hash for EpollCreateFlags
impl Hash for EpollCreateFlags
impl Hash for EpollEvent
impl Hash for EpollEvent
impl Hash for EpollFlags
impl Hash for EpollFlags
impl Hash for AddWatchFlags
impl Hash for AddWatchFlags
impl Hash for otter_api_tests::imports::nix::sys::inotify::WatchDescriptor
impl Hash for otter_api_tests::imports::nix::sys::inotify::WatchDescriptor
impl Hash for MemFdCreateFlag
impl Hash for MemFdCreateFlag
impl Hash for MRemapFlags
impl Hash for MRemapFlags
impl Hash for MlockAllFlags
impl Hash for MlockAllFlags
impl Hash for QuotaValidFlags
impl Hash for QuotaValidFlags
impl Hash for SignalIterator
impl Hash for SignalIterator
impl Hash for signalfd_siginfo
impl Hash for signalfd_siginfo
impl Hash for AcceptConn
impl Hash for AcceptConn
impl Hash for BindToDevice
impl Hash for BindToDevice
impl Hash for IpAddMembership
impl Hash for IpAddMembership
impl Hash for IpDropMembership
impl Hash for IpDropMembership
impl Hash for IpMulticastLoop
impl Hash for IpMulticastLoop
impl Hash for IpMulticastTtl
impl Hash for IpMulticastTtl
impl Hash for IpTransparent
impl Hash for IpTransparent
impl Hash for Ipv4PacketInfo
impl Hash for Ipv4PacketInfo
impl Hash for Ipv6AddMembership
impl Hash for Ipv6AddMembership
impl Hash for Ipv6DropMembership
impl Hash for Ipv6DropMembership
impl Hash for Ipv6RecvPacketInfo
impl Hash for Ipv6RecvPacketInfo
impl Hash for OriginalDst
impl Hash for OriginalDst
impl Hash for PeerCredentials
impl Hash for PeerCredentials
impl Hash for RcvBufForce
impl Hash for RcvBufForce
impl Hash for ReceiveTimeout
impl Hash for ReceiveTimeout
impl Hash for ReceiveTimestamp
impl Hash for ReceiveTimestamp
impl Hash for ReceiveTimestampns
impl Hash for ReceiveTimestampns
impl Hash for SendTimeout
impl Hash for SendTimeout
impl Hash for SndBufForce
impl Hash for SndBufForce
impl Hash for SocketError
impl Hash for SocketError
impl Hash for TcpCongestion
impl Hash for TcpCongestion
impl Hash for TcpKeepCount
impl Hash for TcpKeepCount
impl Hash for TcpKeepIdle
impl Hash for TcpKeepIdle
impl Hash for TcpKeepInterval
impl Hash for TcpKeepInterval
impl Hash for TcpNoDelay
impl Hash for TcpNoDelay
impl Hash for UdpGroSegment
impl Hash for UdpGroSegment
impl Hash for UdpGsoSegment
impl Hash for UdpGsoSegment
impl Hash for NetlinkAddr
impl Hash for NetlinkAddr
impl Hash for sockaddr_in6
impl Hash for sockaddr_in6
impl Hash for sockaddr_in
impl Hash for sockaddr_in
impl Hash for sockaddr_storage
impl Hash for sockaddr_storage
impl Hash for sockaddr_un
impl Hash for sockaddr_un
impl Hash for ControlFlags
impl Hash for ControlFlags
impl Hash for InputFlags
impl Hash for InputFlags
impl Hash for LocalFlags
impl Hash for LocalFlags
impl Hash for OutputFlags
impl Hash for OutputFlags
impl Hash for TimerFlags
impl Hash for TimerFlags
impl Hash for TimerSetTimeFlags
impl Hash for TimerSetTimeFlags
impl Hash for RemoteIoVec
impl Hash for RemoteIoVec
impl Hash for WaitPidFlag
impl Hash for WaitPidFlag
impl Hash for UnixSocketAddr
impl Hash for UnixSocketAddr
URLs hash like their serialization.
impl Hash for AccessFlags
impl Hash for AccessFlags
impl<T> Hash for OrderedFloat<T> where
T: Float,
impl<T> Hash for OrderedFloat<T> where
T: Float,
impl<T> Hash for IsHtmlFormatted<T> where
T: Hash + Display,
impl<T> Hash for IsHtmlFormatted<T> where
T: Hash + Display,
impl<T, N> Hash for GenericArray<T, N> where
T: Hash,
N: ArrayLength<T>,
impl<T, N> Hash for GenericArray<T, N> where
T: Hash,
N: ArrayLength<T>,