Trait ident::IdentCollection
[−]
[src]
pub trait IdentCollection<T, I: Eq = usize> { fn insert_by_ident(
&mut self,
value: WithIdent<T, I>
) -> Option<WithIdent<T, I>>; fn contains_ident(&self, identifier: &I) -> bool; fn get_with_ident(&self, identifier: I) -> Option<WithIdent<&T, I>>; fn get_mut_with_ident(
&mut self,
identifier: I
) -> Option<WithIdent<&mut T, I>>; }
The IdentCollection
trait provides functionality for collections working with
WithIdent
values.
Required Methods
fn insert_by_ident(&mut self, value: WithIdent<T, I>) -> Option<WithIdent<T, I>>
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_ident(a.clone()).is_none()); //Inserting. assert_eq!(a, vec.insert_by_ident(b.clone()).unwrap()); //Updating. assert_eq!(b, vec[0]); //Updated value.
fn contains_ident(&self, identifier: &I) -> bool
Searches for the passed identifier
in the collection.
Params
identifier --- The identifier
to seach for.
fn get_with_ident(&self, identifier: I) -> Option<WithIdent<&T, I>>
Attempts to retrieve a reference to the value with the passed identifier
.
If a reference is found it is returned with the identifier attached.
Params
identifier --- The identifier
to seach for.
fn get_mut_with_ident(&mut self, identifier: I) -> Option<WithIdent<&mut T, I>>
Attempts to retrieve a mutable reference to the value with the passed identifier
.
If a reference is found it is returned with the identifier attached.
Params
identifier --- The identifier
to seach for.
Implementations on Foreign Types
impl<T, I: Eq> IdentCollection<T, I> for Vec<WithIdent<T, I>>
[src]
fn insert_by_ident(&mut self, value: WithIdent<T, I>) -> Option<WithIdent<T, I>>
[src]
fn contains_ident(&self, identifier: &I) -> bool
[src]
fn get_with_ident(&self, identifier: I) -> Option<WithIdent<&T, I>>
[src]
fn get_mut_with_ident(&mut self, identifier: I) -> Option<WithIdent<&mut T, I>>
[src]
impl<T, I: Eq> IdentCollection<T, I> for VecDeque<WithIdent<T, I>>
[src]
fn insert_by_ident(&mut self, value: WithIdent<T, I>) -> Option<WithIdent<T, I>>
[src]
fn contains_ident(&self, identifier: &I) -> bool
[src]
fn get_with_ident(&self, identifier: I) -> Option<WithIdent<&T, I>>
[src]
fn get_mut_with_ident(&mut self, identifier: I) -> Option<WithIdent<&mut T, I>>
[src]
impl<T, I: Eq> IdentCollection<T, I> for LinkedList<WithIdent<T, I>>
[src]
fn insert_by_ident(&mut self, value: WithIdent<T, I>) -> Option<WithIdent<T, I>>
[src]
fn contains_ident(&self, identifier: &I) -> bool
[src]
fn get_with_ident(&self, identifier: I) -> Option<WithIdent<&T, I>>
[src]
fn get_mut_with_ident(&mut self, identifier: I) -> Option<WithIdent<&mut T, I>>
[src]
impl<T, I, S> IdentCollection<T, I> for HashMap<I, T, S> where
I: Eq + Hash + Clone,
S: BuildHasher,
[src]
I: Eq + Hash + Clone,
S: BuildHasher,
fn insert_by_ident(&mut self, value: WithIdent<T, I>) -> Option<WithIdent<T, I>>
[src]
fn contains_ident(&self, identifier: &I) -> bool
[src]
fn get_with_ident(&self, identifier: I) -> Option<WithIdent<&T, I>>
[src]
fn get_mut_with_ident(&mut self, identifier: I) -> Option<WithIdent<&mut T, I>>
[src]
impl<T, I> IdentCollection<T, I> for BTreeMap<I, T> where
I: Eq + Ord + Clone,
[src]
I: Eq + Ord + Clone,