Struct flashmap::ReadHandle
source · [−]pub struct ReadHandle<K, V, S = RandomState> { /* private fields */ }
Expand description
A read handle for the map.
This type allows for the creation of ReadGuard
s, which provide immutable
access to the underlying data.
Implementations
sourceimpl<K, V, S> ReadHandle<K, V, S>
impl<K, V, S> ReadHandle<K, V, S>
sourcepub fn guard(&self) -> View<ReadGuard<'_, K, V, S>>
pub fn guard(&self) -> View<ReadGuard<'_, K, V, S>>
Creates a new ReadGuard
wrapped in a View
, allowing
safe access to the map.
Examples
let (write, read) = flashmap::new::<u32, u32>();
let guard = read.guard();
// The map should be empty since we added nothing to it.
assert!(guard.is_empty());
// Maybe do some more work with the guard
// The guard is released when dropped (you don't have to drop it explicitly)
drop(guard);
In order to see the most recent updates from the writer, a new guard needs to be created:
let (mut write, read) = flashmap::new::<String, String>();
let guard = read.guard();
// This key is not in the map yet
assert!(!guard.contains_key("ferris"));
write.guard().insert("ferris".to_owned(), "crab".to_owned());
// Since we're still using the same guard, the write isn't visible to us yet
assert!(!guard.contains_key("ferris"));
// Drop the old guard and get a new one
drop(guard);
let guard = read.guard();
// The write is now visible
assert_eq!(guard.get("ferris").unwrap(), "crab");
Trait Implementations
sourceimpl<K, V, S> Clone for ReadHandle<K, V, S>
impl<K, V, S> Clone for ReadHandle<K, V, S>
sourceimpl<K, V, S> Drop for ReadHandle<K, V, S>
impl<K, V, S> Drop for ReadHandle<K, V, S>
impl<K, V, S> Send for ReadHandle<K, V, S> where
K: Send + Sync,
V: Send + Sync,
S: Send + Sync,
impl<K, V, S> Sync for ReadHandle<K, V, S> where
K: Send + Sync,
V: Send + Sync,
S: Send + Sync,
Auto Trait Implementations
impl<K, V, S = RandomState> !RefUnwindSafe for ReadHandle<K, V, S>
impl<K, V, S> Unpin for ReadHandle<K, V, S>
impl<K, V, S = RandomState> !UnwindSafe for ReadHandle<K, V, S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more