Trait InternValue

Source
pub trait InternValue {
    type Key: Eq + Hash + Debug + Clone;

    // Required method
    fn into_key(&self) -> Self::Key;

    // Provided method
    fn with_key<F: FnOnce(&Self::Key) -> T, T>(&self, f: F) -> T { ... }
}
Expand description

Trait implemented for the “value” that is being interned.

Required Associated Types§

Source

type Key: Eq + Hash + Debug + Clone

They key used to intern this value by.

Required Methods§

Source

fn into_key(&self) -> Self::Key

Maps the value to a key that will be used to intern it.

Provided Methods§

Source

fn with_key<F: FnOnce(&Self::Key) -> T, T>(&self, f: F) -> T

Calls the given function with the key that was used to intern this value.

This is mainly used to prevent frequent cloning of the key when doing a lookup.

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.

Implementations on Foreign Types§

Source§

impl<A: InternValue + Eq + Hash + Debug + Clone, B: InternValue + Eq + Hash + Debug + Clone> InternValue for (A, B)

Source§

type Key = (A, B)

Source§

fn into_key(&self) -> Self::Key

Source§

fn with_key<F: FnOnce(&Self::Key) -> T, T>(&self, f: F) -> T

Implementors§

Source§

impl<V: InternValueTrivial> InternValue for V

Implement InternValue trivially, that is without actually mapping at all.

Source§

type Key = V