Struct indexlist::Index [−][src]
pub struct Index { /* fields omitted */ }
A reference to an element in the list.
If you have an Index
, you can get or remove the item at that position in
the list.
Generational indexes
Index
employs a "generational index" scheme. A "generation" is a counter,
saved by the IndexList<T>
. This counter increases whenever an item is
removed from the list. Each item in the list keeps track of the generation
it was inserted in.
An Index also keeps track of a generation. When you attempt to manipulate an
item in the list via an Index
, the generations are compared. If the
Index
's generation is older than the item at that position, it is stale,
and so that item will not be returned or removed.
This scheme lets us re-use removed slots in the list, while ensuring that you won't see bad data.
Examples
You can get an Index
by inserting something into the list:
extern crate indexlist; use indexlist::IndexList; let mut list = IndexList::new(); // this is an Index let index = list.push_back(5);
You can also get one with index_of
:
extern crate indexlist; use indexlist::IndexList; let mut list = IndexList::new(); let five = list.push_back(5); let index = list.index_of(&5); assert_eq!(Some(five), index);
Trait Implementations
impl Debug for Index
[src]
impl Debug for Index
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Copy for Index
[src]
impl Copy for Index
impl Clone for Index
[src]
impl Clone for Index
fn clone(&self) -> Index
[src]
fn clone(&self) -> Index
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for Index
[src]
impl PartialEq for Index