Trait HashMapHandle

Source
pub trait HashMapHandle<K, V>
where K: Clone + Debug + Eq + Hash + Send + Sync + 'static, V: Clone + Debug + 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 is_empty(&self) -> bool; }

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.unwrap();
let res = handle.get_key("test").await.unwrap();
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.unwrap();
assert_eq!(res, None);

let handle = actify::Handle::new(std::collections::HashMap::new());
handle.insert("test", 10).await.unwrap();
let old_value = handle.insert("test", 20).await.unwrap();
assert_eq!(old_value, Some(10));
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.unwrap());

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> HashMapHandle<K, V> for Handle<HashMap<K, V>>
where K: Clone + Debug + Eq + Hash + Send + Sync + 'static, V: Clone + Debug + Send + Sync + 'static,