Skip to main content

HashMapHandle

Trait HashMapHandle 

Source
pub trait HashMapHandle<K, V>
where K: Clone + Eq + Hash + Send + Sync + 'static, V: Clone + Send + Sync + 'static,
{ // Required methods async fn get_key(&self, key: K) -> Option<V>; async fn insert(&self, key: K, val: V) -> Option<V>; async fn remove(&self, key: K) -> Option<V>; async fn clear(&self); async fn is_empty(&self) -> bool; async fn keys(&self) -> Vec<K>; async fn values(&self) -> Vec<V>; }
Expand description

Extension methods for Handle<HashMap<K, V>>, exposed as HashMapHandle.

Required Methods§

Source

async fn get_key(&self, key: K) -> Option<V>

Returns a clone of the value corresponding to the key if it exists It is equivalent to the Hashmap get(), but the method name is changed to avoid conflicts with the get() method of the actor in general

§Examples
let handle = Handle::new(HashMap::new());
handle.insert("test", 10).await;
let res = handle.get_key("test").await;
assert_eq!(res, Some(10));
Source

async fn insert(&self, key: K, val: V) -> Option<V>

Inserts a key-value pair into the map. If the map did not have this key present, None is returned. If the map did have this key present, the value is updated, and the old value is returned. In that case the key is not updated.

§Examples
let handle = Handle::new(HashMap::new());
let res = handle.insert("test", 10).await;
assert_eq!(res, None);

let old_value = handle.insert("test", 20).await;
assert_eq!(old_value, Some(10));
Source

async fn remove(&self, key: K) -> Option<V>

Removes a key from the map, returning the value at the key if the key was previously in the map. Equivalent to HashMap::remove.

§Examples
let handle = Handle::new(HashMap::new());
handle.insert("test", 10).await;
let res = handle.remove("test").await;
assert_eq!(res, Some(10));

let res = handle.remove("test").await;
assert_eq!(res, None);
Source

async fn clear(&self)

Clears the map, removing all key-value pairs. Equivalent to HashMap::clear.

§Examples
let handle = Handle::new(HashMap::new());
handle.insert("test", 10).await;
handle.clear().await;
assert!(handle.is_empty().await);
Source

async fn is_empty(&self) -> bool

Returns true if the map contains no elements.

§Examples
let handle = Handle::new(HashMap::<&str, i32>::new());
assert!(handle.is_empty().await);
Source

async fn keys(&self) -> Vec<K>

Returns a Vec of all keys in the map. Equivalent to HashMap::keys, but collected into a Vec.

§Examples
let handle = Handle::new(HashMap::new());
handle.insert("a", 1).await;
handle.insert("b", 2).await;
let mut keys = handle.keys().await;
keys.sort();
assert_eq!(keys, vec!["a", "b"]);
Source

async fn values(&self) -> Vec<V>

Returns a Vec of all values in the map. Equivalent to HashMap::values, but collected into a Vec.

§Examples
let handle = Handle::new(HashMap::new());
handle.insert("a", 1).await;
handle.insert("b", 2).await;
let mut values = handle.values().await;
values.sort();
assert_eq!(values, vec![1, 2]);

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.

Implementors§

Source§

impl<K, V, __V> HashMapHandle<K, V> for Handle<HashMap<K, V>, __V>
where K: Clone + Eq + Hash + Send + Sync + 'static, V: Clone + Send + Sync + 'static,

Extension methods for Handle<HashMap<K, V>>, exposed as HashMapHandle.