Trait ident::IdentCollection[][src]

pub trait IdentCollection<T, I = 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

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.

Searches for the passed identifier in the collection.

Params

identifier --- The identifier to seach for.

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.

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> IdentCollection<T, usize> for Vec<T>
[src]

impl<T, I: Eq> IdentCollection<T, I> for Vec<WithIdent<T, I>>
[src]

impl<T, I: Eq> IdentCollection<T, I> for VecDeque<WithIdent<T, I>>
[src]

impl<T, I: Eq> IdentCollection<T, I> for LinkedList<WithIdent<T, I>>
[src]

impl<T, I: Eq, S> IdentCollection<T, I> for HashMap<I, T, S> where
    I: Hash + Clone,
    S: BuildHasher
[src]

impl<T, I> IdentCollection<T, I> for BTreeMap<I, T> where
    I: Ord + Clone
[src]

Implementors