diff --git a/viz-core/src/handler/after.rs b/viz-core/src/handler/after.rs index 720a4e76..2c23a4ad 100644 --- a/viz-core/src/handler/after.rs +++ b/viz-core/src/handler/after.rs @@ -19,10 +19,8 @@ impl After { impl Handler for After where - I: Send + 'static, H: Handler>, - O: Send + 'static, - F: Handler + Send + Copy, + F: Handler + Send, { type Output = F::Output; diff --git a/viz-core/src/handler/and_then.rs b/viz-core/src/handler/and_then.rs index fd05dd3b..eef7ca4c 100644 --- a/viz-core/src/handler/and_then.rs +++ b/viz-core/src/handler/and_then.rs @@ -19,10 +19,8 @@ impl AndThen { impl Handler for AndThen where - I: Send + 'static, H: Handler>, - O: Send, - F: Handler + Send + Copy, + F: Handler + Send, { type Output = F::Output; diff --git a/viz-core/src/handler/around.rs b/viz-core/src/handler/around.rs index 6a470bd3..8b801b2a 100644 --- a/viz-core/src/handler/around.rs +++ b/viz-core/src/handler/around.rs @@ -22,7 +22,6 @@ impl Around { impl Handler for Around where - I: Send + 'static, H: Handler> + Copy, F: Handler, Output = H::Output>, { diff --git a/viz-core/src/handler/before.rs b/viz-core/src/handler/before.rs index fc8bc3b6..e1720304 100644 --- a/viz-core/src/handler/before.rs +++ b/viz-core/src/handler/before.rs @@ -19,9 +19,8 @@ impl Before { impl Handler for Before where - I: Send + 'static, F: Handler>, - H: Handler> + Send + Copy, + H: Handler> + Send, { type Output = H::Output; diff --git a/viz-core/src/handler/catch_error.rs b/viz-core/src/handler/catch_error.rs index 692f31ce..271bbcf1 100644 --- a/viz-core/src/handler/catch_error.rs +++ b/viz-core/src/handler/catch_error.rs @@ -1,6 +1,8 @@ use std::marker::PhantomData; -use crate::{async_trait, Handler, IntoResponse, Response, Result}; +use futures_util::future::BoxFuture; + +use crate::{Handler, IntoResponse, Response, Result}; /// Catches rejected error while calling the handler. #[derive(Debug)] @@ -36,7 +38,6 @@ impl CatchError { } } -#[async_trait] impl Handler for CatchError where I: Send + 'static, @@ -48,7 +49,7 @@ where { type Output = Result; - async fn call(&self, i: I) -> Self::Output { + fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { match self.h.call(i).await { Ok(r) => Ok(r.into_response()), Err(e) => Ok(self.f.call(e.downcast::()?).await.into_response()), diff --git a/viz-core/src/handler/map.rs b/viz-core/src/handler/map.rs index f65987ab..89f89dc3 100644 --- a/viz-core/src/handler/map.rs +++ b/viz-core/src/handler/map.rs @@ -1,4 +1,4 @@ -use futures_util::{future::BoxFuture, FutureExt, TryFutureExt}; +use futures_util::{future::BoxFuture, TryFutureExt}; use crate::{Handler, Result}; @@ -17,18 +17,15 @@ impl Map { } } -impl Handler for Map +impl Handler for Map where - I: Send + 'static, H: Handler>, - O: Send + 'static, - F: Handler + Copy, + F: FnOnce(O) -> T + Send, { - type Output = H::Output; + type Output = Result; fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { - let f = self.f; - let fut = self.h.call(i).map_ok(move |o| f.call(o)); + let fut = self.h.call(i).map_ok(self.f); Box::pin(fut) } } diff --git a/viz-core/src/handler/map_into_response.rs b/viz-core/src/handler/map_into_response.rs index 4718990d..6757700b 100644 --- a/viz-core/src/handler/map_into_response.rs +++ b/viz-core/src/handler/map_into_response.rs @@ -1,4 +1,6 @@ -use crate::{async_trait, Handler, IntoResponse, Response, Result}; +use futures_util::{future::BoxFuture, TryFutureExt}; + +use crate::{Handler, IntoResponse, Response, Result}; /// Maps the handler's output type to the [`Response`]. #[derive(Debug, Clone)] @@ -12,16 +14,15 @@ impl MapInToResponse { } } -#[async_trait] impl Handler for MapInToResponse where - I: Send + 'static, H: Handler> + Clone, O: IntoResponse + Send, { type Output = Result; - async fn call(&self, i: I) -> Self::Output { - self.0.call(i).await.map(IntoResponse::into_response) + fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + let fut = self.0.call(i).map_ok(IntoResponse::into_response); + Box::pin(fut) } }