diff --git a/src/handler.rs b/src/handler.rs index 0f36a260..10df0889 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -30,8 +30,6 @@ pub trait Handler: Sized { fn layer(self, layer: L) -> Layered where L: Layer>, - >>::Service: Service>, - <>>::Service as Service>>::Error: IntoResponse, { Layered::new(layer.layer(HandlerSvc::new(self))) } @@ -40,7 +38,7 @@ pub trait Handler: Sized { #[async_trait] impl Handler for F where - F: Fn(Request) -> Fut + Send + Sync, + F: FnOnce(Request) -> Fut + Send + Sync, Fut: Future + Send, Res: IntoResponse, { @@ -61,7 +59,7 @@ macro_rules! impl_handler { #[allow(non_snake_case)] impl Handler for F where - F: Fn(Request, $head, $($tail,)*) -> Fut + Send + Sync, + F: FnOnce(Request, $head, $($tail,)*) -> Fut + Send + Sync, Fut: Future + Send, Res: IntoResponse, $head: FromRequest + Send, diff --git a/src/response.rs b/src/response.rs index 5935d70d..377a3364 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,9 +1,9 @@ use crate::Body; use bytes::Bytes; -use http::{HeaderMap, HeaderValue, Response, StatusCode, header}; +use http::{header, HeaderMap, HeaderValue, Response, StatusCode}; use serde::Serialize; use std::convert::Infallible; -use tower::{util::Either, BoxError}; +use tower::util::Either; pub trait IntoResponse { fn into_response(self) -> Response; @@ -174,18 +174,6 @@ impl IntoResponse for BoxIntoResponse { } } -impl IntoResponse for BoxError { - fn into_response(self) -> Response { - // TODO(david): test for know error types like std::io::Error - // or common errors types from tower and map those more appropriately - - Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Body::from(self.to_string())) - .unwrap() - } -} - impl IntoResponse for StatusCode where B: Default, diff --git a/src/routing.rs b/src/routing.rs index 77364959..f59296ad 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -174,7 +174,7 @@ impl RouteBuilder { R: Service, Response = Response, Error = Infallible> + Send + 'static, R::Future: Send, // TODO(david): do we still need default here - B: Default + From + 'static, + B: From + 'static, { let svc = ServiceBuilder::new() .layer(BufferLayer::new(1024)) diff --git a/src/tests.rs b/src/tests.rs index d332256d..fa7e1bfe 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -275,6 +275,8 @@ async fn boxing() { // TODO(david): tests for adding middleware to single services +// TODO(david): tests for nesting services + /// Run a `tower::Service` in the background and get a URI for it. pub async fn run_in_background(svc: S) -> SocketAddr where