Skip to main content

Lookup

Trait Lookup 

Source
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§

Source

fn into_owned(self) -> O

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Lookup<PathBuf> for &Path

Source§

impl Lookup<PathBuf> for Cow<'_, Path>

Source§

impl Lookup<String> for &str

Source§

impl Lookup<String> for Cow<'_, str>

Source§

impl<'a, T> Lookup<Arc<T>> for &'a T
where T: ?Sized + Hash + Eq, Arc<T>: From<&'a T>,

Source§

fn into_owned(self) -> Arc<T> ⓘ

Source§

impl<'a, T> Lookup<Box<T>> for &'a T
where T: ?Sized + Hash + Eq, Box<T>: From<&'a T>,

Source§

fn into_owned(self) -> Box<T>

Source§

impl<A: Hash + Eq + PartialEq<T> + Clone + Lookup<T>, T> Lookup<Vec<T>> for &[A]

Source§

fn into_owned(self) -> Vec<T>

Source§

impl<T: Clone> Lookup<Box<[T]>> for Cow<'_, [T]>

Source§

impl<T: Clone> Lookup<T> for Cow<'_, T>

Source§

fn into_owned(self) -> T

Source§

impl<T: Clone> Lookup<Vec<T>> for Cow<'_, [T]>

Source§

fn into_owned(self) -> Vec<T>

Source§

impl<T> Lookup<T> for &T
where T: Clone,

Source§

fn into_owned(self) -> T

Source§

impl<const N: usize, A: Hash + Eq + PartialEq<T> + Clone + Lookup<T>, T> Lookup<Vec<T>> for [A; N]

Source§

fn into_owned(self) -> Vec<T>

Implementors§

Source§

impl<T> Lookup<T> for T