Trait weak_table::traits::WeakKey[][src]

pub trait WeakKey: WeakElement {
    type Key: ?Sized + Eq + Hash;
    fn with_key<F, R>(view: &Self::Strong, f: F) -> R
    where
        F: FnOnce(&Self::Key) -> R
; fn hash<H: Hasher>(view: &Self::Strong, h: &mut H) { ... }
fn equals<Q>(view: &Self::Strong, key: &Q) -> bool
    where
        Q: ?Sized + Eq,
        Self::Key: Borrow<Q>
, { ... } }
Expand description

Interface for elements that can act as keys in weak hash tables.

To use an element as a weak hash map key or weak hash set element), the hash table needs to be able to view the actual key values to hash and compare them. This trait provides the necessary mechanism.

Associated Types

The underlying key type.

For example, for std::rc::Weak<T>, this will be T.

Required methods

Allows borrowing a view of the key, via a callback.

Rather than returning a borrowed reference to the actual key, this method passes a reference to the key to a callback with an implicit higher-order lifetime bound. This is necessary to get the lifetimes right in cases where the key is not actually store in the strong pointer.

Provided methods

Hashes the key view into the given Hasher.

Returns whether the key view equals the given key.

Implementations on Foreign Types

Implementors