Trait enso_prelude::WeakKey[][src]

pub trait WeakKey: WeakElement {
    type Key: Eq + Hash + ?Sized;
    fn with_key<F, R>(view: &Self::Strong, f: F) -> R
    where
        F: FnOnce(&Self::Key) -> R
; }
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

type Key: Eq + Hash + ?Sized[src]

The underlying key type.

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

Required methods

fn with_key<F, R>(view: &Self::Strong, f: F) -> R where
    F: FnOnce(&Self::Key) -> R, 
[src]

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.

Implementations on Foreign Types

impl<T> WeakKey for Weak<T> where
    T: Eq + Hash + ?Sized
[src]

type Key = T

pub fn with_key<F, R>(view: &<Weak<T> as WeakElement>::Strong, f: F) -> R where
    F: FnOnce(&<Weak<T> as WeakKey>::Key) -> R, 
[src]

Implementors

impl<T> WeakKey for enso_prelude::Weak<T> where
    T: Eq + Hash + ?Sized
[src]

type Key = T

pub fn with_key<F, R>(view: &<Weak<T> as WeakElement>::Strong, f: F) -> R where
    F: FnOnce(&<Weak<T> as WeakKey>::Key) -> R, 
[src]