Skip to main content

StoreMut

Trait StoreMut 

Source
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§

Source

fn insert(&mut self, key: K, value: V) -> Option<V>

Inserts the value identified by the key.

Source

fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Key,

Removes the value identified by the key.

Source

fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Key,

Removes the value identified by the key and returns both.

Source

fn clear(&mut self)

Clears the store, removing all items.

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>
where K: Key, V: Value,

Source§

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>
where K: Borrow<Q>, Q: Key,

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)>
where K: Borrow<Q>, Q: Key,

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§

fn clear(&mut self)

Clears the store, removing all items.

§Examples
use std::collections::BTreeMap;
use zrx_store::StoreMut;

// Create store and initial state
let mut store = BTreeMap::new();
store.insert("key", 42);

// Clear store
store.clear();
assert!(store.is_empty());
Source§

impl<K, V> StoreMut<K, V> for Slab<(K, V)>
where K: Key, V: Value,

Source§

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>
where K: Borrow<Q>, Q: Key,

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)>
where K: Borrow<Q>, Q: Key,

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§

fn clear(&mut self)

Clears the store, removing all items.

§Examples
use slab::Slab;
use zrx_store::StoreMut;

// Create store and initial state
let mut store = Slab::new();
StoreMut::insert(&mut store, "key", 42);

// Clear store
StoreMut::clear(&mut store);
assert!(store.is_empty());
Source§

impl<K, V, S> StoreMut<K, V> for HashMap<K, V, S>
where K: Key, V: Value, S: BuildHasher,

Source§

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>
where K: Borrow<Q>, Q: Key,

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)>
where K: Borrow<Q>, Q: Key,

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)));
Source§

fn clear(&mut self)

Clears the store, removing all items.

§Examples
use std::collections::HashMap;
use zrx_store::StoreMut;

// Create store and initial state
let mut store = HashMap::new();
store.insert("key", 42);

// Clear store
store.clear();
assert!(store.is_empty());

Implementors§

Source§

impl<K, V, S> StoreMut<K, V> for Queue<K, V, S>
where K: Key, V: Value, S: StoreMut<K, Item>,

Source§

impl<K, V, S> StoreMut<K, V> for Stash<K, V, S>
where K: Key, V: Value, S: StoreMut<K, usize>,

Source§

impl<K, V, S, C> StoreMut<K, V> for Indexed<K, V, S, C>
where K: Key, V: Ord, S: StoreMut<K, V>, C: Comparator<V>,

Source§

impl<K, V, S, C> StoreMut<K, V> for Ordered<K, V, S, C>
where K: Key, V: Clone + Ord, S: StoreMut<K, V>, C: Comparator<V> + Clone,