pub trait TryHash {
// Provided method
fn try_hash(&self, _state: &mut dyn Hasher) -> bool { ... }
}
Expand description
Prerequisite for CustomConst
. Allows to declare a custom hash function,
but the easiest options are either to impl TryHash for ... {}
to indicate
“not hashable”, or else to implement/derive Hash.
Provided Methods§
sourcefn try_hash(&self, _state: &mut dyn Hasher) -> bool
fn try_hash(&self, _state: &mut dyn Hasher) -> bool
Hashes the value, if possible; else return false
without mutating the Hasher
.
This relates with CustomConst::equal_consts just like Hash with Eq:
- if
x.equal_consts(y)
==>x.try_hash(s)
behaves equivalently toy.try_hash(s)
- if
x.hash(s)
behaves differently fromy.hash(s)
==>x.equal_consts(y) == false
As with Hash, these requirements can trivially be satisfied by either
equal_consts
always returningfalse
, ortry_hash
always behaving the same (e.g. returningfalse
, as it does by default)
Note: uses dyn
rather than being parametrized by <H: Hasher>
to be object-safe.