Enum symbol_map::indexing::Insertion
[−]
[src]
pub enum Insertion<T> { Present(T), New(T), }
Indicates whether the result of a symbol lookup had to create a new table entry.
Variants
Present(T)
Result came from an item that was already present in table.
New(T)
Result came from an item that was not present in table, and a new entry was created.
Methods
impl<T> Insertion<T>
[src]
fn map<F, X>(&self, f: F) -> Insertion<X> where F: FnOnce(&T) -> X
Maps over the type returned by an Insertion
to produce a new value
that may be of a different type.
Example
use symbol_map::indexing::{HashIndexing, Indexing, Insertion}; use std::str::FromStr; let mut index = HashIndexing::<String, usize>::default(); let s1 = String::from_str("value1").unwrap(); let s2 = String::from_str("value1").unwrap(); let s3 = String::from_str("value2").unwrap(); // get_or_insert normally returns an Insertion that borrows the // structure on which it was invoked. We map the symbol reference // returned after each insertion to a copy of the ID that was mapped to. let id1: Insertion<usize> = index.get_or_insert(s1).map(|symbol| *symbol.id()); let id2: Insertion<usize> = index.get_or_insert(s2).map(|symbol| *symbol.id()); let id3: Insertion<usize> = index.get_or_insert(s3).map(|symbol| *symbol.id()); // The Insertion values are not the same because one was an insertion and // the other a retrieval. assert!(id1 != id2); assert!(id1 != id3); // But the symbol IDs for identical values are the same. assert!(id1.unwrap() == id2.unwrap());
fn unwrap(self) -> T
Unwraps an Insertion
to produce the value which it wraps.
Trait Implementations
impl<T: Clone> Clone for Insertion<T>
[src]
fn clone(&self) -> Insertion<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Eq> Eq for Insertion<T>
[src]
impl<T: Ord> Ord for Insertion<T>
[src]
fn cmp(&self, __arg_0: &Insertion<T>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<T: Hash> Hash for Insertion<T>
[src]
fn hash<__HT: Hasher>(&self, __arg_0: &mut __HT)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl<T: PartialEq> PartialEq for Insertion<T>
[src]
fn eq(&self, __arg_0: &Insertion<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Insertion<T>) -> bool
This method tests for !=
.
impl<T: PartialOrd> PartialOrd for Insertion<T>
[src]
fn partial_cmp(&self, __arg_0: &Insertion<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Insertion<T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Insertion<T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Insertion<T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Insertion<T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more