Many

Trait Many 

Source
pub trait Many<'a, Key> {
    type Ref: 'a;
    type Mut: 'a;

    // Required methods
    fn try_move_ref(&mut self, key: Key) -> Result<Self::Ref>;
    fn try_move_mut(&mut self, key: Key) -> Result<Self::Mut>;

    // Provided methods
    fn move_ref(&mut self, key: Key) -> Self::Ref { ... }
    fn move_mut(&mut self, key: Key) -> Self::Mut { ... }
}
Expand description

Trait for collections which hold different kinds of reference.

This trait provides methods for retrieving references (either immutable or mutable) by moving them out of the collection to preserve the lifetime of the owner.

This is useful when it is needed to get many mutable references on different elements of the owner collection.

See crate documentation for details.

Required Associated Types§

Source

type Ref: 'a

The type of a reference which is being moved out.

Source

type Mut: 'a

The type of a mutable reference which is being moved out.

Required Methods§

Source

fn try_move_ref(&mut self, key: Key) -> Result<Self::Ref>

Tries to move an immutable reference out of this collection.

This function copies an immutable reference or replaces mutable reference with immutable one, preserving an immutable reference in this collection.

Source

fn try_move_mut(&mut self, key: Key) -> Result<Self::Mut>

Tries to move a mutable reference out of this collection.

Provided Methods§

Source

fn move_ref(&mut self, key: Key) -> Self::Ref

Moves an immutable reference out of this collection.

This function copies an immutable reference or replaces mutable reference with immutable one, preserving an immutable reference in this collection.

§Panics

Panics if mutable reference was already moved out of the collection.

Source

fn move_mut(&mut self, key: Key) -> Self::Mut

Moves a mutable reference out of this collection.

§Panics

Panics if mutable reference was already moved out of the collection or the value was already borrowed as immutable.

Implementations on Foreign Types§

Source§

impl<'a, I, Item, Key> Many<'a, PeekableKey<Key>> for Peekable<I>
where I: Iterator<Item = Item>, Item: Many<'a, Key>,

Source§

type Ref = Option<<Item as Many<'a, Key>>::Ref>

Source§

type Mut = Option<<Item as Many<'a, Key>>::Mut>

Source§

fn try_move_ref(&mut self, key: PeekableKey<Key>) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: PeekableKey<Key>) -> Result<Self::Mut>

Source§

impl<'a, K, V> Many<'a, K> for BTreeMap<K, V>
where K: Ord, V: Many<'a, K>,

Available on crate feature alloc only.

Implementation of Many trait for BTreeMap.

Source§

type Ref = Option<<V as Many<'a, K>>::Ref>

Source§

type Mut = Option<<V as Many<'a, K>>::Mut>

Source§

fn try_move_ref(&mut self, key: K) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: K) -> Result<Self::Mut>

Source§

impl<'a, K, V, S> Many<'a, K> for HashMap<K, V, S>
where K: Hash + Eq, V: Many<'a, K>, S: BuildHasher,

Available on crate feature std only.

Implementation of Many trait for HashMap.

Source§

type Ref = Option<<V as Many<'a, K>>::Ref>

Source§

type Mut = Option<<V as Many<'a, K>>::Mut>

Source§

fn try_move_ref(&mut self, key: K) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: K) -> Result<Self::Mut>

Source§

impl<'a, K, V, S> Many<'a, K> for HashMap<K, V, S>
where K: Hash + Eq, V: Many<'a, K>, S: BuildHasher,

Available on crate feature hashbrown only.

Implementation of Many trait for hashbrown::HashMap.

Source§

type Ref = Option<<V as Many<'a, K>>::Ref>

Source§

type Mut = Option<<V as Many<'a, K>>::Mut>

Source§

fn try_move_ref(&mut self, key: K) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: K) -> Result<Self::Mut>

Source§

impl<'a, T> Many<'a, usize> for [T]
where T: Many<'a, usize>,

Implementation of Many trait for slice.

Source§

type Ref = Option<<T as Many<'a, usize>>::Ref>

Source§

type Mut = Option<<T as Many<'a, usize>>::Mut>

Source§

fn try_move_ref(&mut self, key: usize) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: usize) -> Result<Self::Mut>

Source§

impl<'a, T> Many<'a, usize> for VecDeque<T>
where T: Many<'a, usize>,

Available on crate feature alloc only.

Implementation of Many trait for VecDeque.

Source§

type Ref = Option<<T as Many<'a, usize>>::Ref>

Source§

type Mut = Option<<T as Many<'a, usize>>::Mut>

Source§

fn try_move_ref(&mut self, key: usize) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: usize) -> Result<Self::Mut>

Source§

impl<'a, T> Many<'a, usize> for Vec<T>
where T: Many<'a, usize>,

Available on crate feature alloc only.

Implementation of Many trait for Vec.

Source§

type Ref = Option<<T as Many<'a, usize>>::Ref>

Source§

type Mut = Option<<T as Many<'a, usize>>::Mut>

Source§

fn try_move_ref(&mut self, key: usize) -> Result<Self::Ref>

Source§

fn try_move_mut(&mut self, key: usize) -> Result<Self::Mut>

Implementors§

Source§

impl<'owner, T, K> Many<'owner, K> for T
where T: ?Sized + Move<'owner>,

Many trait can be implemented for any type which implements Move trait for any key.

Source§

type Ref = <T as MoveRef<'owner>>::Ref

Source§

type Mut = <T as MoveMut<'owner>>::Mut