pub trait StoreMut<K, V>: Store<K, V> {
// Required methods
fn insert(&mut self, key: K, value: V) -> Option<V>;
fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>,
Q: Key;
fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>,
Q: Key;
fn clear(&mut self);
}Expand description
Mutable store.
This trait extends Store, requiring further additional mutable methods
which can be used to alter the store, like inserting and removing items.
§Examples
use std::collections::HashMap;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = HashMap::new();
store.insert("key", 42);
// Remove value from store
let value = store.remove(&"key");
assert_eq!(value, Some(42));Required Methods§
Sourcefn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes the value identified by the key and returns both.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<K, V> StoreMut<K, V> for BTreeMap<K, V>
impl<K, V> StoreMut<K, V> for BTreeMap<K, V>
Source§fn insert(&mut self, key: K, value: V) -> Option<V>
fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts the value identified by the key.
§Examples
use std::collections::BTreeMap;
use zrx_store::StoreMut;
// Create store
let mut store = BTreeMap::new();
// Insert value
let value = store.insert("key", 42);
assert_eq!(value, None);Source§fn remove<Q>(&mut self, key: &Q) -> Option<V>
fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes the value identified by the key.
§Examples
use std::collections::BTreeMap;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = BTreeMap::new();
store.insert("key", 42);
// Remove and return value
let value = store.remove(&"key");
assert_eq!(value, Some(42));Source§fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes the value identified by the key and returns both.
§Examples
use std::collections::BTreeMap;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = BTreeMap::new();
store.insert("key", 42);
// Remove and return entry
let entry = store.remove_entry(&"key");
assert_eq!(entry, Some(("key", 42)));Source§impl<K, V> StoreMut<K, V> for Slab<(K, V)>
impl<K, V> StoreMut<K, V> for Slab<(K, V)>
Source§fn insert(&mut self, key: K, value: V) -> Option<V>
fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts the value identified by the key.
§Examples
use slab::Slab;
use zrx_store::StoreMut;
// Create store
let mut store = Slab::new();
// Insert value
let value = StoreMut::insert(&mut store, "key", 42);
assert_eq!(value, None);Source§fn remove<Q>(&mut self, key: &Q) -> Option<V>
fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes the value identified by the key.
§Examples
use slab::Slab;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = Slab::new();
StoreMut::insert(&mut store, "key", 42);
// Remove and return value
let value = StoreMut::remove(&mut store, &"key");
assert_eq!(value, Some(42));Source§fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes the value identified by the key and returns both.
§Examples
use slab::Slab;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = Slab::new();
StoreMut::insert(&mut store, "key", 42);
// Remove and return entry
let entry = StoreMut::remove_entry(&mut store, &"key");
assert_eq!(entry, Some(("key", 42)));Source§impl<K, V, S> StoreMut<K, V> for HashMap<K, V, S>
impl<K, V, S> StoreMut<K, V> for HashMap<K, V, S>
Source§fn insert(&mut self, key: K, value: V) -> Option<V>
fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts the value identified by the key.
§Examples
use std::collections::HashMap;
use zrx_store::StoreMut;
// Create store
let mut store = HashMap::new();
// Insert value
let value = store.insert("key", 42);
assert_eq!(value, None);Source§fn remove<Q>(&mut self, key: &Q) -> Option<V>
fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes the value identified by the key.
§Examples
use std::collections::HashMap;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = HashMap::new();
store.insert("key", 42);
// Remove and return value
let value = store.remove(&"key");
assert_eq!(value, Some(42));Source§fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes the value identified by the key and returns both.
§Examples
use std::collections::HashMap;
use zrx_store::StoreMut;
// Create store and initial state
let mut store = HashMap::new();
store.insert("key", 42);
// Remove and return entry
let entry = store.remove_entry(&"key");
assert_eq!(entry, Some(("key", 42)));