pub trait WeakKey: WeakElement {
type Key: ?Sized + Eq + Hash;
// Required method
fn with_key<F, R>(view: &Self::Strong, f: F) -> R
where F: FnOnce(&Self::Key) -> R;
// Provided methods
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.
Required Associated Types§
Required Methods§
Sourcefn with_key<F, R>(view: &Self::Strong, f: F) -> R
fn with_key<F, R>(view: &Self::Strong, f: F) -> R
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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.