Trait otter_api_tests::shapelib::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
1.3.0[src]fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 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
The hash of an array is the same as that of the corresponding slice,
as required by the Borrow implementation.
#![feature(build_hasher_simple_hash_one)] use std::hash::BuildHasher; let b = std::collections::hash_map::RandomState::new(); let a: [u8; 3] = [0xa8, 0x3c, 0x09]; let s: &[u8] = &[0xa8, 0x3c, 0x09]; assert_eq!(b.hash_one(a), b.hash_one(s));
The hash of a vector is the same as that of the corresponding slice,
as required by the core::borrow::Borrow implementation.
#![feature(build_hasher_simple_hash_one)] use std::hash::BuildHasher; let b = std::collections::hash_map::RandomState::new(); let v: Vec<u8> = vec![0xa8, 0x3c, 0x09]; let s: &[u8] = &[0xa8, 0x3c, 0x09]; assert_eq!(b.hash_one(v), b.hash_one(s));
impl<'data> Hash for ObjectMapEntry<'data>
impl<'data> Hash for ObjectMapEntry<'data>impl<'data> Hash for SymbolMapName<'data>
impl<'data> Hash for SymbolMapName<'data>impl<'data> Hash for CompressedData<'data>
impl<'data> Hash for CompressedData<'data>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);
Case-insensitive hashing
impl<F, A> Hash for Tendril<F, A> where
A: Atomicity,
F: Format,
impl<F, A> Hash for Tendril<F, A> where
A: Atomicity,
F: Format, impl<Static> Hash for Atom<Static> where
Static: StaticAtomSet,
impl<Static> Hash for Atom<Static> where
Static: StaticAtomSet, impl<T> Hash for NonZeroPtrMut<T> where
T: 'static,
impl<T> Hash for NonZeroPtrMut<T> where
T: 'static, Implementors
impl Hash for WriteStyleimpl Hash for PosixFadviseAdviceimpl Hash for AioCancelStatimpl Hash for AioFsyncModeimpl Hash for MmapAdviseimpl Hash for RebootModeimpl Hash for SigHandlerimpl Hash for SigevNotifyimpl Hash for SigmaskHowimpl Hash for AddressFamilyimpl Hash for SockProtocolimpl Hash for SpecialCharacterIndicesimpl Hash for WaitStatusimpl Hash for PathconfVarimpl Hash for SysconfVarimpl Hash for otter_api_tests::shapelib::LittleEndianimpl Hash for Elf32_Chdrimpl Hash for Elf32_Ehdrimpl Hash for Elf32_Phdrimpl Hash for Elf32_Shdrimpl Hash for Elf64_Chdrimpl Hash for Elf64_Ehdrimpl Hash for Elf64_Phdrimpl Hash for Elf64_Shdrimpl Hash for __c_anonymous_sockaddr_can_j1939impl Hash for __c_anonymous_sockaddr_can_tpimpl Hash for __exit_statusimpl Hash for _libc_fpstateimpl Hash for _libc_fpxregimpl Hash for _libc_xmmregimpl Hash for arpd_requestimpl Hash for arpreq_oldimpl Hash for can_filterimpl Hash for dl_phdr_infoimpl Hash for epoll_eventimpl Hash for fanotify_event_metadataimpl Hash for fanotify_responseimpl Hash for ff_condition_effectimpl Hash for ff_constant_effectimpl Hash for ff_envelopeimpl Hash for ff_periodic_effectimpl Hash for ff_ramp_effectimpl Hash for ff_rumble_effectimpl Hash for ff_triggerimpl Hash for genlmsghdrimpl Hash for if_nameindeximpl Hash for in6_pktinfoimpl Hash for in_pktinfoimpl Hash for inotify_eventimpl Hash for input_absinfoimpl Hash for input_eventimpl Hash for input_keymap_entryimpl Hash for input_maskimpl Hash for ip_mreq_sourceimpl Hash for itimerspecimpl Hash for mcontext_timpl Hash for nl_mmap_hdrimpl Hash for nl_mmap_reqimpl Hash for nl_pktinfoimpl Hash for ntptimevalimpl Hash for packet_mreqimpl Hash for posix_spawn_file_actions_timpl Hash for posix_spawnattr_timpl Hash for pthread_attr_timpl Hash for pthread_cond_timpl Hash for pthread_condattr_timpl Hash for pthread_mutex_timpl Hash for pthread_mutexattr_timpl Hash for pthread_rwlock_timpl Hash for pthread_rwlockattr_timpl Hash for regmatch_timpl Hash for sched_paramimpl Hash for seccomp_dataimpl Hash for sock_extended_errimpl Hash for sock_filterimpl Hash for sock_fprogimpl Hash for sockaddr_algimpl Hash for sockaddr_llimpl Hash for sockaddr_nlimpl Hash for sockaddr_vmimpl Hash for statx_timestampimpl Hash for ucontext_timpl Hash for uinput_abs_setupimpl Hash for uinput_ff_eraseimpl Hash for uinput_ff_uploadimpl Hash for uinput_setupimpl Hash for uinput_user_devimpl Hash for user_fpregs_structimpl Hash for user_regs_structimpl Hash for OwningIterimpl Hash for FallocateFlagsimpl Hash for RenameFlagsimpl Hash for SpliceFFlagsimpl Hash for InterfaceAddressimpl Hash for InterfaceAddressIteratorimpl Hash for DeleteModuleFlagsimpl Hash for ModuleInitFlagsimpl Hash for InterfaceFlagsimpl Hash for OpenptyResultimpl Hash for CloneFlagsimpl Hash for EpollCreateFlagsimpl Hash for EpollEventimpl Hash for EpollFlagsimpl Hash for AddWatchFlagsimpl Hash for otter_api_tests::imports::nix::sys::inotify::WatchDescriptorimpl Hash for MemFdCreateFlagimpl Hash for MRemapFlagsimpl Hash for MlockAllFlagsimpl Hash for QuotaValidFlagsimpl Hash for SignalIteratorimpl Hash for signalfd_siginfoimpl Hash for AcceptConnimpl Hash for BindToDeviceimpl Hash for IpAddMembershipimpl Hash for IpDropMembershipimpl Hash for IpFreebindimpl Hash for IpMulticastLoopimpl Hash for IpMulticastTtlimpl Hash for IpTransparentimpl Hash for Ipv4PacketInfoimpl Hash for Ipv6AddMembershipimpl Hash for Ipv6DropMembershipimpl Hash for Ipv6RecvPacketInfoimpl Hash for OriginalDstimpl Hash for PeerCredentialsimpl Hash for RcvBufForceimpl Hash for ReceiveTimeoutimpl Hash for ReceiveTimestampimpl Hash for ReceiveTimestampnsimpl Hash for SendTimeoutimpl Hash for SndBufForceimpl Hash for SocketErrorimpl Hash for TcpCongestionimpl Hash for TcpKeepCountimpl Hash for TcpKeepIdleimpl Hash for TcpKeepIntervalimpl Hash for TcpNoDelayimpl Hash for TcpUserTimeoutimpl Hash for UdpGroSegmentimpl Hash for UdpGsoSegmentimpl Hash for NetlinkAddrimpl Hash for sockaddr_in6impl Hash for sockaddr_inimpl Hash for sockaddr_storageimpl Hash for sockaddr_unimpl Hash for ControlFlagsimpl Hash for InputFlagsimpl Hash for LocalFlagsimpl Hash for OutputFlagsimpl Hash for TimerFlagsimpl Hash for TimerSetTimeFlagsimpl Hash for RemoteIoVecimpl Hash for WaitPidFlagimpl Hash for UnixSocketAddrimpl Hash for AccessFlagsimpl<T> Hash for IsHtmlFormatted<T> where
T: Hash + Display, impl<T> Hash for OrderedFloat<T> where
T: Float, impl<T, N> Hash for GenericArray<T, N> where
T: Hash,
N: ArrayLength<T>,