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 hashed 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 WriteStyleimpl Hash for PosixFadviseAdvice
impl Hash for PosixFadviseAdviceimpl Hash for AioCancelStat
impl Hash for AioCancelStatimpl Hash for AioFsyncMode
impl Hash for AioFsyncModeimpl Hash for MmapAdvise
impl Hash for MmapAdviseimpl Hash for RebootMode
impl Hash for RebootModeimpl Hash for SigHandler
impl Hash for SigHandlerimpl Hash for SigevNotify
impl Hash for SigevNotifyimpl Hash for SigmaskHow
impl Hash for SigmaskHowimpl Hash for AddressFamily
impl Hash for AddressFamilyimpl Hash for SockProtocol
impl Hash for SockProtocolimpl Hash for SpecialCharacterIndices
impl Hash for SpecialCharacterIndicesimpl Hash for WaitStatus
impl Hash for WaitStatusimpl Hash for otter_api_tests::shapelib::LittleEndian
impl Hash for otter_api_tests::shapelib::LittleEndianimpl Hash for PathconfVar
impl Hash for PathconfVarimpl Hash for SysconfVar
impl Hash for SysconfVarNaiveDateTime 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_Chdrimpl Hash for Elf32_Ehdr
impl Hash for Elf32_Ehdrimpl Hash for Elf32_Phdr
impl Hash for Elf32_Phdrimpl Hash for Elf32_Shdr
impl Hash for Elf32_Shdrimpl Hash for Elf64_Chdr
impl Hash for Elf64_Chdrimpl Hash for Elf64_Ehdr
impl Hash for Elf64_Ehdrimpl Hash for Elf64_Phdr
impl Hash for Elf64_Phdrimpl Hash for Elf64_Shdr
impl Hash for Elf64_Shdrimpl Hash for __c_anonymous_sockaddr_can_j1939
impl Hash for __c_anonymous_sockaddr_can_j1939impl Hash for __c_anonymous_sockaddr_can_tp
impl Hash for __c_anonymous_sockaddr_can_tpimpl Hash for __exit_status
impl Hash for __exit_statusimpl Hash for _libc_fpstate
impl Hash for _libc_fpstateimpl Hash for _libc_fpxreg
impl Hash for _libc_fpxregimpl Hash for _libc_xmmreg
impl Hash for _libc_xmmregimpl Hash for arpd_request
impl Hash for arpd_requestimpl Hash for arpreq_old
impl Hash for arpreq_oldimpl Hash for can_filter
impl Hash for can_filterimpl Hash for dl_phdr_info
impl Hash for dl_phdr_infoimpl Hash for epoll_event
impl Hash for epoll_eventimpl Hash for fanotify_event_metadata
impl Hash for fanotify_event_metadataimpl Hash for fanotify_response
impl Hash for fanotify_responseimpl Hash for ff_condition_effect
impl Hash for ff_condition_effectimpl Hash for ff_constant_effect
impl Hash for ff_constant_effectimpl Hash for ff_envelope
impl Hash for ff_envelopeimpl Hash for ff_periodic_effect
impl Hash for ff_periodic_effectimpl Hash for ff_ramp_effect
impl Hash for ff_ramp_effectimpl Hash for ff_rumble_effect
impl Hash for ff_rumble_effectimpl Hash for ff_trigger
impl Hash for ff_triggerimpl Hash for genlmsghdr
impl Hash for genlmsghdrimpl Hash for if_nameindex
impl Hash for if_nameindeximpl Hash for in6_pktinfo
impl Hash for in6_pktinfoimpl Hash for in_pktinfo
impl Hash for in_pktinfoimpl Hash for inotify_event
impl Hash for inotify_eventimpl Hash for input_absinfo
impl Hash for input_absinfoimpl Hash for input_event
impl Hash for input_eventimpl Hash for input_keymap_entry
impl Hash for input_keymap_entryimpl Hash for input_mask
impl Hash for input_maskimpl Hash for ip_mreq_source
impl Hash for ip_mreq_sourceimpl Hash for itimerspec
impl Hash for itimerspecimpl Hash for mcontext_t
impl Hash for mcontext_timpl Hash for nl_mmap_hdr
impl Hash for nl_mmap_hdrimpl Hash for nl_mmap_req
impl Hash for nl_mmap_reqimpl Hash for nl_pktinfo
impl Hash for nl_pktinfoimpl Hash for ntptimeval
impl Hash for ntptimevalimpl Hash for packet_mreq
impl Hash for packet_mreqimpl Hash for posix_spawn_file_actions_t
impl Hash for posix_spawn_file_actions_timpl Hash for posix_spawnattr_t
impl Hash for posix_spawnattr_timpl Hash for pthread_attr_t
impl Hash for pthread_attr_timpl Hash for pthread_cond_t
impl Hash for pthread_cond_timpl Hash for pthread_condattr_t
impl Hash for pthread_condattr_timpl Hash for pthread_mutex_t
impl Hash for pthread_mutex_timpl Hash for pthread_mutexattr_t
impl Hash for pthread_mutexattr_timpl Hash for pthread_rwlock_t
impl Hash for pthread_rwlock_timpl Hash for pthread_rwlockattr_t
impl Hash for pthread_rwlockattr_timpl Hash for regmatch_t
impl Hash for regmatch_timpl Hash for sched_param
impl Hash for sched_paramimpl Hash for sock_extended_err
impl Hash for sock_extended_errimpl Hash for sockaddr_alg
impl Hash for sockaddr_algimpl Hash for sockaddr_ll
impl Hash for sockaddr_llimpl Hash for sockaddr_nl
impl Hash for sockaddr_nlimpl Hash for sockaddr_vm
impl Hash for sockaddr_vmimpl Hash for statx_timestamp
impl Hash for statx_timestampimpl Hash for ucontext_t
impl Hash for ucontext_timpl Hash for uinput_abs_setup
impl Hash for uinput_abs_setupimpl Hash for uinput_ff_erase
impl Hash for uinput_ff_eraseimpl Hash for uinput_ff_upload
impl Hash for uinput_ff_uploadimpl Hash for uinput_setup
impl Hash for uinput_setupimpl Hash for uinput_user_dev
impl Hash for uinput_user_devimpl Hash for user_fpregs_struct
impl Hash for user_fpregs_structimpl Hash for user_regs_struct
impl Hash for user_regs_structimpl Hash for OwningIter
impl Hash for OwningIterimpl Hash for FallocateFlags
impl Hash for FallocateFlagsimpl Hash for SpliceFFlags
impl Hash for SpliceFFlagsimpl Hash for InterfaceAddress
impl Hash for InterfaceAddressimpl Hash for InterfaceAddressIterator
impl Hash for InterfaceAddressIteratorimpl Hash for DeleteModuleFlags
impl Hash for DeleteModuleFlagsimpl Hash for ModuleInitFlags
impl Hash for ModuleInitFlagsimpl Hash for InterfaceFlags
impl Hash for InterfaceFlagsimpl Hash for OpenptyResult
impl Hash for OpenptyResultimpl Hash for CloneFlags
impl Hash for CloneFlagsimpl Hash for EpollCreateFlags
impl Hash for EpollCreateFlagsimpl Hash for EpollEvent
impl Hash for EpollEventimpl Hash for EpollFlags
impl Hash for EpollFlagsimpl Hash for AddWatchFlags
impl Hash for AddWatchFlagsimpl Hash for otter_api_tests::imports::nix::sys::inotify::WatchDescriptor
impl Hash for otter_api_tests::imports::nix::sys::inotify::WatchDescriptorimpl Hash for MemFdCreateFlag
impl Hash for MemFdCreateFlagimpl Hash for MRemapFlags
impl Hash for MRemapFlagsimpl Hash for MlockAllFlags
impl Hash for MlockAllFlagsimpl Hash for QuotaValidFlags
impl Hash for QuotaValidFlagsimpl Hash for SignalIterator
impl Hash for SignalIteratorimpl Hash for signalfd_siginfo
impl Hash for signalfd_siginfoimpl Hash for AcceptConn
impl Hash for AcceptConnimpl Hash for BindToDevice
impl Hash for BindToDeviceimpl Hash for IpAddMembership
impl Hash for IpAddMembershipimpl Hash for IpDropMembership
impl Hash for IpDropMembershipimpl Hash for IpMulticastLoop
impl Hash for IpMulticastLoopimpl Hash for IpMulticastTtl
impl Hash for IpMulticastTtlimpl Hash for IpTransparent
impl Hash for IpTransparentimpl Hash for Ipv4PacketInfo
impl Hash for Ipv4PacketInfoimpl Hash for Ipv6AddMembership
impl Hash for Ipv6AddMembershipimpl Hash for Ipv6DropMembership
impl Hash for Ipv6DropMembershipimpl Hash for Ipv6RecvPacketInfo
impl Hash for Ipv6RecvPacketInfoimpl Hash for OriginalDst
impl Hash for OriginalDstimpl Hash for PeerCredentials
impl Hash for PeerCredentialsimpl Hash for RcvBufForce
impl Hash for RcvBufForceimpl Hash for ReceiveTimeout
impl Hash for ReceiveTimeoutimpl Hash for ReceiveTimestamp
impl Hash for ReceiveTimestampimpl Hash for ReceiveTimestampns
impl Hash for ReceiveTimestampnsimpl Hash for SendTimeout
impl Hash for SendTimeoutimpl Hash for SndBufForce
impl Hash for SndBufForceimpl Hash for SocketError
impl Hash for SocketErrorimpl Hash for TcpCongestion
impl Hash for TcpCongestionimpl Hash for TcpKeepCount
impl Hash for TcpKeepCountimpl Hash for TcpKeepIdle
impl Hash for TcpKeepIdleimpl Hash for TcpKeepInterval
impl Hash for TcpKeepIntervalimpl Hash for TcpNoDelay
impl Hash for TcpNoDelayimpl Hash for UdpGroSegment
impl Hash for UdpGroSegmentimpl Hash for UdpGsoSegment
impl Hash for UdpGsoSegmentimpl Hash for NetlinkAddr
impl Hash for NetlinkAddrimpl Hash for sockaddr_in6
impl Hash for sockaddr_in6impl Hash for sockaddr_in
impl Hash for sockaddr_inimpl Hash for sockaddr_storage
impl Hash for sockaddr_storageimpl Hash for sockaddr_un
impl Hash for sockaddr_unimpl Hash for ControlFlags
impl Hash for ControlFlagsimpl Hash for InputFlags
impl Hash for InputFlagsimpl Hash for LocalFlags
impl Hash for LocalFlagsimpl Hash for OutputFlags
impl Hash for OutputFlagsimpl Hash for TimerFlags
impl Hash for TimerFlagsimpl Hash for TimerSetTimeFlags
impl Hash for TimerSetTimeFlagsimpl Hash for RemoteIoVec
impl Hash for RemoteIoVecimpl Hash for WaitPidFlag
impl Hash for WaitPidFlagimpl Hash for UnixSocketAddr
impl Hash for UnixSocketAddrURLs hash like their serialization.
impl Hash for AccessFlags
impl Hash for AccessFlagsimpl<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>,