Struct foxbox_taxonomy::transact::InsertInMap
[−]
[src]
pub struct InsertInMap<'a, K, V> where K: 'a + Clone + Hash + Eq, V: 'a {
// some fields omitted
}
Insert a (key, value) pair in a map. However, if the object is dropped before method commit()
is called, the insertion is cancelled.
Example
use std::collections::HashMap; use foxbox_taxonomy::transact::InsertInMap; let mut map = HashMap::new(); { let transaction = InsertInMap::start(&mut map, vec![(1, 1)]).unwrap(); if some_condition { transaction.commit(); } } // At this stage, if we have not called `transaction.commit()`, the // insertion is cancelled.
Methods
impl<'a, K, V> InsertInMap<'a, K, V> where K: 'a + Clone + Hash + Eq, V: 'a
fn start(map: &'a mut HashMap<K, V>, data: Vec<(K, V)>) -> Result<Self, K>
Insert (key, value) pairs in a map, reversibly, and without overwriting.
If one of the keys k
is already present in the map, this is a noop, and the
result is Err(k)
. Otherwise, the result is Ok(transaction)
. In the latter
case, if transaction
is dropped before transaction.commit()
is called,
the insertion is cancelled.
fn commit(self)
Commit the transaction. Once this is done, the value may be dropped without cancelling the insertion.