use std::future::Future;
use std::pin::Pin;
use crate::error::Result;
use crate::model::types::Message;
pub trait Memory: Send + Sync {
fn add_message(&self, message: Message) -> impl Future<Output = Result<()>> + Send;
fn get_messages(&self) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn clear(&self) -> impl Future<Output = Result<()>> + Send;
}
pub trait ErasedMemory: Send + Sync {
fn add_message_erased<'a>(
&'a self,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
fn get_messages_erased<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'a>>;
fn clear_erased<'a>(&'a self) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
}
impl<T: Memory> ErasedMemory for T {
fn add_message_erased<'a>(
&'a self,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Box::pin(self.add_message(message))
}
fn get_messages_erased<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'a>> {
Box::pin(self.get_messages())
}
fn clear_erased<'a>(&'a self) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Box::pin(self.clear())
}
}
pub type SharedMemory = std::sync::Arc<dyn ErasedMemory>;