#![crate_name = "async_map"]
#![macro_use]
#[doc(hidden)] pub mod lockingmap;
pub mod non_locking_map;
pub mod single_writer_versioned;
mod versioned_map;
use std::borrow::Borrow;
use std::future::Future;
use std::hash::Hash;
use std::pin::Pin;
pub use versioned_map::VersionedMap;
pub trait AsyncStorable: Clone + Send + Sync + std::fmt::Debug + Unpin + 'static {}
impl<T: Clone + Send + Sync + Unpin + std::fmt::Debug + 'static> AsyncStorable for T {}
pub trait AsyncKey: AsyncStorable + Hash + Eq {}
impl<T: AsyncStorable + Hash + Eq> AsyncKey for T {}
pub trait AsyncFactory<K: AsyncKey, V: AsyncStorable>:
(Fn(&K) -> V) + Send + Sync + 'static
{
}
impl<K: AsyncKey, V: AsyncStorable, F: (Fn(&K) -> V) + Send + Sync + 'static> AsyncFactory<K, V>
for F
{
}
pub trait FactoryBorrow<K: AsyncKey, V: AsyncStorable>:
Borrow<dyn AsyncFactory<K, V>> + Send + Unpin + 'static
{
}
impl<K: AsyncKey, V: AsyncStorable, T: Borrow<dyn AsyncFactory<K, V>> + Send + Unpin + 'static>
FactoryBorrow<K, V> for T
{
}
pub trait AsyncMap: Clone + Send {
type Key: AsyncKey;
type Value: AsyncStorable;
fn get_if_present(&self, key: &Self::Key) -> Option<Self::Value>;
fn get<'a, 'b, B: FactoryBorrow<Self::Key, Self::Value>>(
&'a self,
key: &'a Self::Key,
factory: B,
) -> Pin<Box<dyn Future<Output = Self::Value> + Send + 'b>>;
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}