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