use std::future::Future;
use std::pin::Pin;
use crate::context::Context;
use crate::response::{IntoResponse, Response};
pub type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send + 'static>>;
pub trait Handler: Send + Sync + 'static {
fn call(&self, ctx: Context) -> BoxFuture<Response>;
}
impl<F, Fut, R> Handler for F
where
F: Fn(Context) -> Fut + Send + Sync + 'static,
Fut: Future<Output = R> + Send + 'static,
R: IntoResponse,
{
fn call(&self, ctx: Context) -> BoxFuture<Response> {
let fut = self(ctx);
Box::pin(async move { fut.await.into_response() })
}
}