pub struct WriteHandle<K, V, S = RandomState> where
    K: Hash + Eq,
    S: BuildHasher
{ /* private fields */ }
Expand description

A write handle to the underlying map.

This type allows for the creation of WriteGuards which allow for mutation of the underlying map.

Implementations

Blocks the calling thread until all readers see the same version of the map.

If all readers already see the same version of the map (or if there are no active readers) then this function is a no-op.

This function is meant for advanced use only. See Leaked::into_inner for an example use-case.

Creates a new WriteGuard wrapped in a View, allowing for safe read and write access to the map.

Examples
let (mut write, read) = flashmap::new::<String, String>();

let mut guard = write.guard();

// Insert a few values
guard.insert("apple".to_owned(), "red".to_owned());
guard.insert("banana".to_owned(), "yellow".to_owned());

// Remove a value
assert_eq!(&*guard.remove("apple".to_owned()).unwrap(), "red");

// Publishing makes all previous changes visible to new readers. Dropping the
// guard has the same effect.
guard.publish();

Unlike a read guard, when reading through a write guard, all changes will be immediately visible.

let (mut write, read) = flashmap::new::<String, String>();

let mut guard = write.guard();

// Our insert is immediately visible to us
guard.insert("apple".to_owned(), "red".to_owned());
assert_eq!(guard.get("apple").unwrap(), "red");
assert!(!guard.contains_key("banana"));

guard.insert("banana".to_owned(), "yellow".to_owned());
assert_eq!(guard.get("banana").unwrap(), "yellow");

// Likewise, removes (and all other operations) are immediately visible
assert_eq!(&*guard.remove("apple".to_owned()).unwrap(), "red");
assert!(!guard.contains_key("apple"));

Reclaims a leaked value, providing ownership of the underlying value.

Panics

Panics if the leaked value provided came from a different map then the one this handle is associated with.

Examples
use flashmap::{self, Evicted};

let (mut write, read) = flashmap::new::<String, String>();

write.guard().insert("ferris".to_owned(), "crab".to_owned());

// ~~ stuff happens ~~

let leaked = write.guard().remove("ferris".to_owned())
    .map(Evicted::leak)
    .unwrap();

let value = write.reclaim_one(leaked);
assert_eq!(value, "crab");

Returns a function which can safely reclaim leaked values. This is useful for reclaiming multiple leaked values while only performign the necessary synchronization once.

Panics

The returned function will panic if given a leaked value not from the map this handle is associated with. This function itself will not panic.

Examples
use flashmap::{self, Evicted};

let (mut write, read) = flashmap::new::<u32, String>();

let mut guard = write.guard();
guard.insert(0xFF0000, "red".to_owned());
guard.insert(0x00FF00, "green".to_owned());
guard.insert(0x0000FF, "blue".to_owned());
guard.publish();

// ~~ stuff happens ~~

let mut guard = write.guard();
let colors = [0xFF0000, 0x00FF00, 0x0000FF].map(|hex| {
    guard.remove(hex).map(Evicted::leak).unwrap()
});
guard.publish();

let [red, green, blue] = colors.map(write.reclaimer());

assert_eq!(red, "red");
assert_eq!(green, "green");
assert_eq!(blue, "blue");

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.