pub trait Lookup<O> {
// Required method
fn into_owned(self) -> O;
}Expand description
The Lookup trait is a more flexible variant on std::borrow::Borrow
and std::borrow::ToOwned.
It is implemented by “some type that can be used as the lookup key for O”.
This means that self can be hashed and compared for equality with values
of type O without actually creating an owned value. It self needs to be interned,
it can be converted into an equivalent value of type O.
The canonical example is &str: Lookup<String>. However, this example
alone can be handled by std::borrow::Borrow. In our case, we may have
multiple keys accumulated into a struct, like ViewStruct: Lookup<(K1, ...)>,
where struct ViewStruct<L1: Lookup<K1>...>(K1...). The Borrow trait
requires that &(K1...) be convertible to &ViewStruct which just isn’t
possible. Lookup instead offers direct hash and eq methods.
Required Methods§
fn into_owned(self) -> O
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".