hugr_core::ops::constant

Trait TryHash

source
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§

source

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 to y.try_hash(s)
  • if x.hash(s) behaves differently from y.hash(s) ==> x.equal_consts(y) == false

As with Hash, these requirements can trivially be satisfied by either

  • equal_consts always returning false, or
  • try_hash always behaving the same (e.g. returning false, as it does by default)

Note: uses dyn rather than being parametrized by <H: Hasher> to be object-safe.

Implementors§