use crate::server::{
Event,
controlchan::{Reply, error::ControlChanError},
};
use async_trait::async_trait;
use std::{future::Future, pin::Pin};
#[async_trait]
pub trait ControlChanMiddleware: Send + Sync {
async fn handle(&mut self, e: Event) -> Result<Reply, ControlChanError>;
}
#[async_trait]
impl<Function> ControlChanMiddleware for Function
where
Function: Send + Sync + Fn(Event) -> Pin<Box<dyn Future<Output = Result<Reply, ControlChanError>> + Send>>,
{
async fn handle(&mut self, e: Event) -> Result<Reply, ControlChanError> {
(self)(e).await
}
}