Struct evmap::WriteHandle
[−]
[src]
pub struct WriteHandle<K, V, M = (), S = RandomState> where
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone, { /* fields omitted */ }
A handle that may be used to modify the eventually consistent map.
Note that any changes made to the map will not be made visible to readers until refresh()
is
called.
Examples
let x = ('x', 42); let (r, mut w) = evmap::new(); // the map is uninitialized, so all lookups should return None assert_eq!(r.get_and(&x.0, |rs| rs.len()), None); w.refresh(); // after the first refresh, it is empty, but ready assert_eq!(r.get_and(&x.0, |rs| rs.len()), None); w.insert(x.0, x); // it is empty even after an add (we haven't refresh yet) assert_eq!(r.get_and(&x.0, |rs| rs.len()), None); w.refresh(); // but after the swap, the record is there! assert_eq!(r.get_and(&x.0, |rs| rs.len()), Some(1)); assert_eq!(r.get_and(&x.0, |rs| rs.iter().any(|v| v.0 == x.0 && v.1 == x.1)), Some(true));
Methods
impl<K, V, M, S> WriteHandle<K, V, M, S> where
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
[src]
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
fn refresh(&mut self)
[src]
Refresh the handle used by readers so that pending writes are made visible.
This method needs to wait for all readers to move to the new handle so that it can replay the operational log onto the stale map copy the readers used to use. This can take some time, especially if readers are executing slow operations, or if there are many of them.
fn set_meta(&mut self, meta: M) -> M
[src]
Set the metadata.
Will only be visible to readers after the next call to refresh()
.
fn insert(&mut self, k: K, v: V)
[src]
Add the given value to the value-set of the given key.
The updated value-set will only be visible to readers after the next call to refresh()
.
fn update(&mut self, k: K, v: V)
[src]
Replace the value-set of the given key with the given value.
The new value will only be visible to readers after the next call to refresh()
.
fn clear(&mut self, k: K)
[src]
Clear the value-set of the given key, without removing it.
This will allocate an empty value-set for the key if it does not already exist.
The new value will only be visible to readers after the next call to refresh()
.
fn remove(&mut self, k: K, v: V)
[src]
Remove the given value from the value-set of the given key.
The updated value-set will only be visible to readers after the next call to refresh()
.
fn empty(&mut self, k: K)
[src]
Remove the value-set for the given key.
The value-set will only disappear from readers after the next call to refresh()
.
Methods from Deref<Target = ReadHandle<K, V, M, S>>
fn len(&self) -> usize
[src]
Returns the number of non-empty keys present in the map.
fn is_empty(&self) -> bool
[src]
Returns true if the map contains no elements.
fn meta(&self) -> M
[src]
Get the current meta value.
fn get_and<Q: ?Sized, F, T>(&self, key: &Q, then: F) -> Option<T> where
F: FnOnce(&[V]) -> T,
K: Borrow<Q>,
Q: Hash + Eq,
[src]
F: FnOnce(&[V]) -> T,
K: Borrow<Q>,
Q: Hash + Eq,
Applies a function to the values corresponding to the key, and returns the result.
The key may be any borrowed form of the map's key type, but Hash
and Eq
on the borrowed
form must match those for the key type.
Note that not all writes will be included with this read -- only those that have been
refreshed by the writer. If no refresh has happened, this function returns None
.
If no values exist for the given key, the function will not be called, and None
will be
returned.
fn meta_get_and<Q: ?Sized, F, T>(
&self,
key: &Q,
then: F
) -> Option<(Option<T>, M)> where
F: FnOnce(&[V]) -> T,
K: Borrow<Q>,
Q: Hash + Eq,
[src]
&self,
key: &Q,
then: F
) -> Option<(Option<T>, M)> where
F: FnOnce(&[V]) -> T,
K: Borrow<Q>,
Q: Hash + Eq,
Applies a function to the values corresponding to the key, and returns the result alongside the meta information.
The key may be any borrowed form of the map's key type, but Hash
and Eq
on the borrowed
form must match those for the key type.
Note that not all writes will be included with this read -- only those that have been
refreshed by the writer. If no refresh has happened, this function returns None
.
If no values exist for the given key, the function will not be called, and Some(None, _)
will be returned.
fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Returns true if the map contains any values for the specified key.
The key may be any borrowed form of the map's key type, but Hash
and Eq
on the borrowed
form must match those for the key type.
fn for_each<F>(&self, f: F) where
F: FnMut(&K, &[V]),
[src]
F: FnMut(&K, &[V]),
Read all values in the map, and transform them into a new collection.
Be careful with this function! While the iteration is ongoing, any writer that tries to refresh will block waiting on this reader to finish.
fn map_into<Map, Collector, Target>(&self, f: Map) -> Collector where
Map: FnMut(&K, &[V]) -> Target,
Collector: FromIterator<Target>,
[src]
Map: FnMut(&K, &[V]) -> Target,
Collector: FromIterator<Target>,
Read all values in the map, and transform them into a new collection.
Trait Implementations
impl<K, V, M, S> Drop for WriteHandle<K, V, M, S> where
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
[src]
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
impl<K, V, M, S> Extend<(K, V)> for WriteHandle<K, V, M, S> where
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
[src]
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
[src]
Extends a collection with the contents of an iterator. Read more
impl<K, V, M, S> Deref for WriteHandle<K, V, M, S> where
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
[src]
K: Eq + Hash + Clone,
S: BuildHasher + Default,
V: Eq + ShallowCopy,
M: 'static + Clone,
type Target = ReadHandle<K, V, M, S>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.