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§
Required Methods§
Sourcefn try_move_ref(&mut self, key: Key) -> Result<Self::Ref>
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.
Sourcefn try_move_mut(&mut self, key: Key) -> Result<Self::Mut>
fn try_move_mut(&mut self, key: Key) -> Result<Self::Mut>
Tries to move a mutable reference out of this collection.
Provided Methods§
Sourcefn move_ref(&mut self, key: Key) -> Self::Ref
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.
Implementations on Foreign Types§
Source§impl<'a, I, Item, Key> Many<'a, PeekableKey<Key>> for Peekable<I>
impl<'a, I, Item, Key> Many<'a, PeekableKey<Key>> for Peekable<I>
Source§impl<'a, K, V, S> Many<'a, K> for HashMap<K, V, S>
Available on crate feature hashbrown only.Implementation of Many trait for hashbrown::HashMap.
impl<'a, K, V, S> Many<'a, K> for HashMap<K, V, S>
hashbrown only.Implementation of Many trait for hashbrown::HashMap.