CollectionRef

Trait CollectionRef 

Source
pub trait CollectionRef: Collection {
    type ItemRef<'a>: Clone + Deref<Target = Self::Item>
       where Self: 'a;

    // Required method
    fn upcast_item_ref<'short, 'long: 'short>(
        r: Self::ItemRef<'long>,
    ) -> Self::ItemRef<'short>
       where Self: 'long;
}
Expand description

Abstract collection that can be immutably referenced.

Required Associated Types§

Source

type ItemRef<'a>: Clone + Deref<Target = Self::Item> where Self: 'a

Type of references to items of the collection.

Required Methods§

Source

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Changes an item reference into a shorter lived reference.

Item references are covariant with regard to the defined lifetime parameter 'a. Since this cannot be directly expressed by the type system, this associated function allows one to explicitly shorten the reference’s lifetime.

You can use the covariant_item_ref! macro to automatically implement this function.

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<K, V> CollectionRef for BTreeMap<K, V>

Source§

type ItemRef<'a> = &'a V where Self: 'a

Source§

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Source§

impl<K, V> CollectionRef for HashMap<K, V>

Source§

type ItemRef<'a> = &'a V where Self: 'a

Source§

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Source§

impl<T> CollectionRef for BTreeSet<T>

Source§

type ItemRef<'a> = &'a T where Self: 'a

Source§

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Source§

impl<T> CollectionRef for VecDeque<T>

Source§

type ItemRef<'a> = &'a T where Self: 'a

Source§

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Source§

impl<T> CollectionRef for Vec<T>

Source§

type ItemRef<'a> = &'a T where Self: 'a

Source§

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Source§

impl<T> CollectionRef for HashSet<T>

Source§

type ItemRef<'a> = &'a T where Self: 'a

Source§

fn upcast_item_ref<'short, 'long: 'short>( r: Self::ItemRef<'long>, ) -> Self::ItemRef<'short>
where Self: 'long,

Implementors§