pub enum Insertion<T> {
Present(T),
New(T),
}Expand description
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.
Implementations§
Source§impl<T> Insertion<T>
impl<T> Insertion<T>
Sourcepub fn map<F, X>(&self, f: F) -> Insertion<X>
pub fn map<F, X>(&self, f: F) -> Insertion<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());Trait Implementations§
Source§impl<T: Ord> Ord for Insertion<T>
impl<T: Ord> Ord for Insertion<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Insertion<T>
impl<T: PartialOrd> PartialOrd for Insertion<T>
impl<T: Eq> Eq for Insertion<T>
impl<T> StructuralPartialEq for Insertion<T>
Auto Trait Implementations§
impl<T> Freeze for Insertion<T>where
T: Freeze,
impl<T> RefUnwindSafe for Insertion<T>where
T: RefUnwindSafe,
impl<T> Send for Insertion<T>where
T: Send,
impl<T> Sync for Insertion<T>where
T: Sync,
impl<T> Unpin for Insertion<T>where
T: Unpin,
impl<T> UnwindSafe for Insertion<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more