luct_core/store/async.rs
1pub trait AsyncStoreRead<K, V> {
2 /// Returns the value associated with `key` from the [`Store`](crate::store::Store)
3 ///
4 /// # Arguments:
5 /// - `key`: the key indexing the object
6 ///
7 /// # Returns:
8 /// - `Some(value)`, if the value exists
9 /// - `None` otherwise
10 fn get(&self, key: K) -> impl Future<Output = Option<V>>;
11
12 /// Returns the number of elements in the [`Store`](crate::store::Store)
13 fn len(&self) -> impl Future<Output = usize>;
14
15 /// Returns `true`, if the store is empty
16 fn is_empty(&self) -> impl Future<Output = bool> {
17 async { self.len().await == 0 }
18 }
19}
20
21pub trait AsyncStoreWrite<K, V> {
22 /// Insert a value into the store
23 ///
24 /// # Arguments:
25 /// - `key`: the key associated with the value
26 /// - `value`: the value itself
27 fn insert(&self, key: K, value: V) -> impl Future<Output = ()>;
28}
29
30/// The [`AsyncStore`] trait is a version of the [`Store`](crate::store::Store) that is asynchrounous
31///
32/// This allows the underlying store engine to make asynchronous requests,
33/// such as a distributed storage or rebuilding the store dynamically using tiles
34pub trait AsyncStore<K, V>: AsyncStoreRead<K, V> + AsyncStoreWrite<K, V> {}
35
36impl<K, V, T> AsyncStore<K, V> for T where T: AsyncStoreRead<K, V> + AsyncStoreWrite<K, V> {}