use std::future::Future;
use std::pin::Pin;
use super::next::Next;
use crate::error::Error;
use crate::request::Request;
use crate::response::Response;
pub type BoxFuture<T = Result> = Pin<Box<dyn Future<Output = T> + Send>>;
pub type Result<T = Response> = std::result::Result<T, Error>;
pub trait Middleware<App>: Send + Sync {
fn call(&self, request: Request<App>, next: Next<App>) -> BoxFuture;
}
impl<T, Await, App> Middleware<App> for T
where
T: Fn(Request<App>, Next<App>) -> Await + Send + Sync,
Await: Future<Output = Result> + Send + 'static,
{
fn call(&self, request: Request<App>, next: Next<App>) -> BoxFuture {
Box::pin(self(request, next))
}
}