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

Result came from an item that was already present in table.

Result came from an item that was not present in table, and a new entry was created.

Methods

impl<T> Insertion<T>
[src]

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());

Unwraps an Insertion to produce the value which it wraps.

Trait Implementations

impl<T: Clone> Clone for Insertion<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Eq> Eq for Insertion<T>
[src]

impl<T: Ord> Ord for Insertion<T>
[src]

This method returns an Ordering between self and other. Read more

impl<T: Hash> Hash for Insertion<T>
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.

impl<T: PartialEq> PartialEq for Insertion<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: PartialOrd> PartialOrd for Insertion<T>
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more