Trait ident::IdentCollection
[−]
[src]
pub trait IdentCollection<T, I = usize, E = WithIdent<T, I>> where
E: BorrowMut<WithIdent<T, I>>,
I: Eq, { fn insert_by_id(&mut self, value: E) -> Option<E>; fn contains_id(&self, identifier: &I) -> bool; fn get_with_id(&self, identifier: &I) -> Option<&E>; fn get_mut_with_id(&mut self, identifier: &I) -> Option<&mut E>; }
The IdentCollection
trait provides functionality for collections working with
WithIdent
values.
Required Methods
fn insert_by_id(&mut self, value: E) -> Option<E>
Inserts the passed value or updates the first value found with an equal identifier
.
If a value is updated the old value is returned in a Some(value)
.
Examples
let mut vec = Vec::with_capacity(1); let a = WithIdent::new(1, 5); let b = WithIdent::new(1, 10); assert!(vec.insert_by_id(a.clone()).is_none()); //Inserting. assert_eq!(*a, *vec.insert_by_id(b.clone()).unwrap()); //Updating. assert_eq!(*b, *vec[0]); //Updated value.
fn contains_id(&self, identifier: &I) -> bool
Searches for the passed identifier
in the collection.
Params
identifier --- The identifier
to seach for.
fn get_with_id(&self, identifier: &I) -> Option<&E>
Attempts to retrieve a reference to the value with the passed identifier
.
Params
identifier --- The identifier
to seach for.
fn get_mut_with_id(&mut self, identifier: &I) -> Option<&mut E>
Attempts to retrieve a mutable reference to the value with the passed identifier
.
Params
identifier --- The identifier
to seach for.
Implementations on Foreign Types
impl<T, I, E> IdentCollection<T, I, E> for Vec<E> where
E: BorrowMut<WithIdent<T, I>>,
I: Eq,
[src]
E: BorrowMut<WithIdent<T, I>>,
I: Eq,
fn insert_by_id(&mut self, value: E) -> Option<E>
[src]
fn contains_id(&self, identifier: &I) -> bool
[src]
fn get_with_id(&self, identifier: &I) -> Option<&E>
[src]
fn get_mut_with_id(&mut self, identifier: &I) -> Option<&mut E>
[src]
impl<T, I, E> IdentCollection<T, I, E> for VecDeque<E> where
E: BorrowMut<WithIdent<T, I>>,
I: Eq,
[src]
E: BorrowMut<WithIdent<T, I>>,
I: Eq,
fn insert_by_id(&mut self, value: E) -> Option<E>
[src]
fn contains_id(&self, identifier: &I) -> bool
[src]
fn get_with_id(&self, identifier: &I) -> Option<&E>
[src]
fn get_mut_with_id(&mut self, identifier: &I) -> Option<&mut E>
[src]
impl<T, I, E> IdentCollection<T, I, E> for LinkedList<E> where
E: BorrowMut<WithIdent<T, I>>,
I: Eq,
[src]
E: BorrowMut<WithIdent<T, I>>,
I: Eq,