pub trait HashMapHandle<K, V>{
// 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§
Sourceasync fn get_key(&self, key: K) -> Option<V>
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));Sourceasync fn insert(&self, key: K, val: V) -> Option<V>
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));Sourceasync fn remove(&self, key: K) -> Option<V>
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);Sourceasync fn clear(&self)
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);Sourceasync fn is_empty(&self) -> bool
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);Sourceasync fn keys(&self) -> Vec<K>
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"]);Sourceasync fn values(&self) -> Vec<V>
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.