diff --git a/axum-extra/src/extract/cookie/mod.rs b/axum-extra/src/extract/cookie/mod.rs index ca05c83631..3e12155b19 100644 --- a/axum-extra/src/extract/cookie/mod.rs +++ b/axum-extra/src/extract/cookie/mod.rs @@ -255,7 +255,7 @@ mod tests { custom_key: CustomKey(Key::generate()), }; - let app = Router::<_, Body>::new() + let app = Router::new() .route("/set", get(set_cookie)) .route("/get", get(get_cookie)) .route("/remove", get(remove_cookie)) @@ -352,7 +352,7 @@ mod tests { custom_key: CustomKey(Key::generate()), }; - let app = Router::<_, Body>::new() + let app = Router::new() .route("/get", get(get_cookie)) .with_state(state); diff --git a/axum-extra/src/extract/form.rs b/axum-extra/src/extract/form.rs index df33e5cade..1f660c4511 100644 --- a/axum-extra/src/extract/form.rs +++ b/axum-extra/src/extract/form.rs @@ -1,9 +1,9 @@ use axum::{ async_trait, - body::HttpBody, + body::Body, extract::{rejection::RawFormRejection, FromRequest, RawForm}, response::{IntoResponse, Response}, - BoxError, Error, RequestExt, + Error, RequestExt, }; use http::{Request, StatusCode}; use serde::de::DeserializeOwned; @@ -52,17 +52,14 @@ impl Deref for Form { } #[async_trait] -impl FromRequest for Form +impl FromRequest for Form where T: DeserializeOwned, - B: HttpBody + Send + 'static, - B::Data: Send, - B::Error: Into, S: Send + Sync, { type Rejection = FormRejection; - async fn from_request(req: Request, _state: &S) -> Result { + async fn from_request(req: Request, _state: &S) -> Result { let RawForm(bytes) = req .extract() .await diff --git a/axum-extra/src/extract/with_rejection.rs b/axum-extra/src/extract/with_rejection.rs index f3a0f04e87..c5b9c326f7 100644 --- a/axum-extra/src/extract/with_rejection.rs +++ b/axum-extra/src/extract/with_rejection.rs @@ -1,4 +1,5 @@ use axum::async_trait; +use axum::body::Body; use axum::extract::{FromRequest, FromRequestParts}; use axum::response::IntoResponse; use http::request::Parts; @@ -109,16 +110,15 @@ impl DerefMut for WithRejection { } #[async_trait] -impl FromRequest for WithRejection +impl FromRequest for WithRejection where - B: Send + 'static, S: Send + Sync, - E: FromRequest, + E: FromRequest, R: From + IntoResponse, { type Rejection = R; - async fn from_request(req: Request, state: &S) -> Result { + async fn from_request(req: Request, state: &S) -> Result { let extractor = E::from_request(req, state).await?; Ok(WithRejection(extractor, PhantomData)) } @@ -180,7 +180,7 @@ mod tests { } } - let req = Request::new(()); + let req = Request::new(Body::empty()); let result = WithRejection::::from_request(req, &()).await; assert!(matches!(result, Err(TestRejection))); diff --git a/axum-extra/src/handler/mod.rs b/axum-extra/src/handler/mod.rs index 305c9c8ccf..275f8418cd 100644 --- a/axum-extra/src/handler/mod.rs +++ b/axum-extra/src/handler/mod.rs @@ -1,5 +1,6 @@ //! Additional handler utilities. +use axum::body::Body; use axum::{ extract::FromRequest, handler::Handler, @@ -19,15 +20,15 @@ pub use self::or::Or; /// /// The drawbacks of this trait is that you cannot apply middleware to individual handlers like you /// can with [`Handler::layer`]. -pub trait HandlerCallWithExtractors: Sized { +pub trait HandlerCallWithExtractors: Sized { /// The type of future calling this handler returns. type Future: Future + Send + 'static; /// Call the handler with the extracted inputs. - fn call(self, extractors: T, state: S) -> >::Future; + fn call(self, extractors: T, state: S) -> >::Future; /// Conver this `HandlerCallWithExtractors` into [`Handler`]. - fn into_handler(self) -> IntoHandler { + fn into_handler(self) -> IntoHandler { IntoHandler { handler: self, _marker: PhantomData, @@ -102,9 +103,9 @@ pub trait HandlerCallWithExtractors: Sized { /// ); /// # let _: Router = app; /// ``` - fn or(self, rhs: R) -> Or + fn or(self, rhs: R) -> Or where - R: HandlerCallWithExtractors, + R: HandlerCallWithExtractors, { Or { lhs: self, @@ -117,7 +118,7 @@ pub trait HandlerCallWithExtractors: Sized { macro_rules! impl_handler_call_with { ( $($ty:ident),* $(,)? ) => { #[allow(non_snake_case)] - impl HandlerCallWithExtractors<($($ty,)*), S, B> for F + impl HandlerCallWithExtractors<($($ty,)*), S> for F where F: FnOnce($($ty,)*) -> Fut, Fut: Future + Send + 'static, @@ -130,7 +131,7 @@ macro_rules! impl_handler_call_with { self, ($($ty,)*): ($($ty,)*), _state: S, - ) -> >::Future { + ) -> >::Future { self($($ty,)*).map(IntoResponse::into_response) } } @@ -159,22 +160,22 @@ impl_handler_call_with!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, /// /// Created with [`HandlerCallWithExtractors::into_handler`]. #[allow(missing_debug_implementations)] -pub struct IntoHandler { +pub struct IntoHandler { handler: H, - _marker: PhantomData (T, S, B)>, + _marker: PhantomData (T, S)>, } -impl Handler for IntoHandler +impl Handler for IntoHandler where - H: HandlerCallWithExtractors + Clone + Send + 'static, - T: FromRequest + Send + 'static, + H: HandlerCallWithExtractors + Clone + Send + 'static, + T: FromRequest + Send + 'static, T::Rejection: Send, - B: Send + 'static, S: Send + Sync + 'static, { type Future = BoxFuture<'static, Response>; - fn call(self, req: http::Request, state: S) -> Self::Future { + fn call(self, req: http::Request, state: S) -> Self::Future { + let req = req.map(Body::new); Box::pin(async move { match T::from_request(req, &state).await { Ok(t) => self.handler.call(t, state).await, @@ -184,9 +185,9 @@ where } } -impl Copy for IntoHandler where H: Copy {} +impl Copy for IntoHandler where H: Copy {} -impl Clone for IntoHandler +impl Clone for IntoHandler where H: Clone, { diff --git a/axum-extra/src/handler/or.rs b/axum-extra/src/handler/or.rs index 2ef24e7145..b23ae5d4ee 100644 --- a/axum-extra/src/handler/or.rs +++ b/axum-extra/src/handler/or.rs @@ -1,6 +1,7 @@ use super::HandlerCallWithExtractors; use crate::either::Either; use axum::{ + body::Body, extract::{FromRequest, FromRequestParts}, handler::Handler, http::Request, @@ -14,19 +15,18 @@ use std::{future::Future, marker::PhantomData}; /// /// Created with [`HandlerCallWithExtractors::or`](super::HandlerCallWithExtractors::or). #[allow(missing_debug_implementations)] -pub struct Or { +pub struct Or { pub(super) lhs: L, pub(super) rhs: R, - pub(super) _marker: PhantomData (Lt, Rt, S, B)>, + pub(super) _marker: PhantomData (Lt, Rt, S)>, } -impl HandlerCallWithExtractors, S, B> for Or +impl HandlerCallWithExtractors, S> for Or where - L: HandlerCallWithExtractors + Send + 'static, - R: HandlerCallWithExtractors + Send + 'static, + L: HandlerCallWithExtractors + Send + 'static, + R: HandlerCallWithExtractors + Send + 'static, Rt: Send + 'static, Lt: Send + 'static, - B: Send + 'static, { // this puts `futures_util` in our public API but thats fine in axum-extra type Future = EitherFuture< @@ -38,7 +38,7 @@ where self, extractors: Either, state: S, - ) -> , S, B>>::Future { + ) -> , S>>::Future { match extractors { Either::E1(lt) => self .lhs @@ -54,21 +54,20 @@ where } } -impl Handler<(M, Lt, Rt), S, B> for Or +impl Handler<(M, Lt, Rt), S> for Or where - L: HandlerCallWithExtractors + Clone + Send + 'static, - R: HandlerCallWithExtractors + Clone + Send + 'static, + L: HandlerCallWithExtractors + Clone + Send + 'static, + R: HandlerCallWithExtractors + Clone + Send + 'static, Lt: FromRequestParts + Send + 'static, - Rt: FromRequest + Send + 'static, + Rt: FromRequest + Send + 'static, Lt::Rejection: Send, Rt::Rejection: Send, - B: Send + 'static, S: Send + Sync + 'static, { // this puts `futures_util` in our public API but thats fine in axum-extra type Future = BoxFuture<'static, Response>; - fn call(self, req: Request, state: S) -> Self::Future { + fn call(self, req: Request, state: S) -> Self::Future { Box::pin(async move { let (mut parts, body) = req.into_parts(); @@ -86,14 +85,14 @@ where } } -impl Copy for Or +impl Copy for Or where L: Copy, R: Copy, { } -impl Clone for Or +impl Clone for Or where L: Clone, R: Clone, diff --git a/axum-extra/src/json_lines.rs b/axum-extra/src/json_lines.rs index 83336311ca..fb76beb939 100644 --- a/axum-extra/src/json_lines.rs +++ b/axum-extra/src/json_lines.rs @@ -2,12 +2,12 @@ use axum::{ async_trait, - body::{HttpBody, StreamBody}, + body::{Body, StreamBody}, extract::FromRequest, response::{IntoResponse, Response}, BoxError, }; -use bytes::{BufMut, Bytes, BytesMut}; +use bytes::{BufMut, BytesMut}; use futures_util::stream::{BoxStream, Stream, TryStream, TryStreamExt}; use http::Request; use pin_project_lite::pin_project; @@ -100,26 +100,19 @@ impl JsonLines { } #[async_trait] -impl FromRequest for JsonLines +impl FromRequest for JsonLines where - B: HttpBody + Send + 'static, - B::Data: Into, - B::Error: Into, T: DeserializeOwned, S: Send + Sync, { type Rejection = Infallible; - async fn from_request(req: Request, _state: &S) -> Result { + async fn from_request(req: Request, _state: &S) -> Result { // `Stream::lines` isn't a thing so we have to convert it into an `AsyncRead` // so we can call `AsyncRead::lines` and then convert it back to a `Stream` - let body = BodyStream { - body: req.into_body(), - }; + let body = req.into_body(); - let stream = body - .map_ok(Into::into) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err)); + let stream = TryStreamExt::map_err(body, |err| io::Error::new(io::ErrorKind::Other, err)); let read = StreamReader::new(stream); let lines_stream = LinesStream::new(read.lines()); @@ -139,26 +132,6 @@ where } } -// like `axum::extract::BodyStream` except it doesn't box the inner body -// we don't need that since we box the final stream in `Inner::Extractor` -pin_project! { - struct BodyStream { - #[pin] - body: B, - } -} - -impl Stream for BodyStream -where - B: HttpBody + Send + 'static, -{ - type Item = Result; - - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.project().body.poll_data(cx) - } -} - impl Stream for JsonLines { type Item = Result; diff --git a/axum-extra/src/protobuf.rs b/axum-extra/src/protobuf.rs index ddb70122e6..3bd4939a33 100644 --- a/axum-extra/src/protobuf.rs +++ b/axum-extra/src/protobuf.rs @@ -2,12 +2,11 @@ use axum::{ async_trait, - body::{Bytes, HttpBody}, + body::Body, extract::{rejection::BytesRejection, FromRequest}, response::{IntoResponse, Response}, - BoxError, }; -use bytes::BytesMut; +use bytes::{Bytes, BytesMut}; use http::{Request, StatusCode}; use prost::Message; use std::ops::{Deref, DerefMut}; @@ -97,17 +96,14 @@ use std::ops::{Deref, DerefMut}; pub struct ProtoBuf(pub T); #[async_trait] -impl FromRequest for ProtoBuf +impl FromRequest for ProtoBuf where T: Message + Default, - B: HttpBody + Send + 'static, - B::Data: Send, - B::Error: Into, S: Send + Sync, { type Rejection = ProtoBufRejection; - async fn from_request(req: Request, state: &S) -> Result { + async fn from_request(req: Request, state: &S) -> Result { let mut bytes = Bytes::from_request(req, state).await?; match T::decode(&mut bytes) { diff --git a/axum-extra/src/routing/mod.rs b/axum-extra/src/routing/mod.rs index 2eef0bc625..dd002b6069 100644 --- a/axum-extra/src/routing/mod.rs +++ b/axum-extra/src/routing/mod.rs @@ -1,6 +1,7 @@ //! Additional types for defining routes. use axum::{ + body::Body, http::Request, response::{IntoResponse, Redirect, Response}, routing::{any, MethodRouter}, @@ -32,7 +33,7 @@ pub use self::typed::{SecondElementIs, TypedPath}; pub use self::spa::SpaRouter; /// Extension trait that adds additional methods to [`Router`]. -pub trait RouterExt: sealed::Sealed { +pub trait RouterExt: sealed::Sealed { /// Add a typed `GET` route to the router. /// /// The path will be inferred from the first argument to the handler function which must @@ -42,7 +43,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_get(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -55,7 +56,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_delete(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -68,7 +69,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_head(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -81,7 +82,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_options(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -94,7 +95,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_patch(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -107,7 +108,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_post(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -120,7 +121,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_put(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -133,7 +134,7 @@ pub trait RouterExt: sealed::Sealed { #[cfg(feature = "typed-routing")] fn typed_trace(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath; @@ -162,7 +163,7 @@ pub trait RouterExt: sealed::Sealed { /// .route_with_tsr("/bar/", get(|| async {})); /// # let _: Router = app; /// ``` - fn route_with_tsr(self, path: &str, method_router: MethodRouter) -> Self + fn route_with_tsr(self, path: &str, method_router: MethodRouter) -> Self where Self: Sized; @@ -171,21 +172,20 @@ pub trait RouterExt: sealed::Sealed { /// This works like [`RouterExt::route_with_tsr`] but accepts any [`Service`]. fn route_service_with_tsr(self, path: &str, service: T) -> Self where - T: Service, Error = Infallible> + Clone + Send + 'static, + T: Service, Error = Infallible> + Clone + Send + 'static, T::Response: IntoResponse, T::Future: Send + 'static, Self: Sized; } -impl RouterExt for Router +impl RouterExt for Router where - B: axum::body::HttpBody + Send + 'static, S: Clone + Send + Sync + 'static, { #[cfg(feature = "typed-routing")] fn typed_get(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -195,7 +195,7 @@ where #[cfg(feature = "typed-routing")] fn typed_delete(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -205,7 +205,7 @@ where #[cfg(feature = "typed-routing")] fn typed_head(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -215,7 +215,7 @@ where #[cfg(feature = "typed-routing")] fn typed_options(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -225,7 +225,7 @@ where #[cfg(feature = "typed-routing")] fn typed_patch(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -235,7 +235,7 @@ where #[cfg(feature = "typed-routing")] fn typed_post(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -245,7 +245,7 @@ where #[cfg(feature = "typed-routing")] fn typed_put(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -255,7 +255,7 @@ where #[cfg(feature = "typed-routing")] fn typed_trace(self, handler: H) -> Self where - H: axum::handler::Handler, + H: axum::handler::Handler, T: SecondElementIs

+ 'static, P: TypedPath, { @@ -263,7 +263,7 @@ where } #[track_caller] - fn route_with_tsr(mut self, path: &str, method_router: MethodRouter) -> Self + fn route_with_tsr(mut self, path: &str, method_router: MethodRouter) -> Self where Self: Sized, { @@ -275,7 +275,7 @@ where #[track_caller] fn route_service_with_tsr(mut self, path: &str, service: T) -> Self where - T: Service, Error = Infallible> + Clone + Send + 'static, + T: Service, Error = Infallible> + Clone + Send + 'static, T::Response: IntoResponse, T::Future: Send + 'static, Self: Sized, @@ -293,9 +293,8 @@ fn validate_tsr_path(path: &str) { } } -fn add_tsr_redirect_route(router: Router, path: &str) -> Router +fn add_tsr_redirect_route(router: Router, path: &str) -> Router where - B: axum::body::HttpBody + Send + 'static, S: Clone + Send + Sync + 'static, { async fn redirect_handler(uri: Uri) -> Response { @@ -343,7 +342,7 @@ where mod sealed { pub trait Sealed {} - impl Sealed for axum::Router {} + impl Sealed for axum::Router {} } #[cfg(test)] diff --git a/axum-extra/src/routing/resource.rs b/axum-extra/src/routing/resource.rs index 11f49d22b8..ea1fbd6c54 100644 --- a/axum-extra/src/routing/resource.rs +++ b/axum-extra/src/routing/resource.rs @@ -1,5 +1,4 @@ use axum::{ - body::Body, handler::Handler, routing::{delete, get, on, post, MethodFilter, MethodRouter}, Router, @@ -33,14 +32,13 @@ use axum::{ /// # let _: Router = app; /// ``` #[derive(Debug)] -pub struct Resource { +pub struct Resource { pub(crate) name: String, - pub(crate) router: Router, + pub(crate) router: Router, } -impl Resource +impl Resource where - B: axum::body::HttpBody + Send + 'static, S: Clone + Send + Sync + 'static, { /// Create a `Resource` with the given name. @@ -56,7 +54,7 @@ where /// Add a handler at `GET /{resource_name}`. pub fn index(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = self.index_create_path(); @@ -66,7 +64,7 @@ where /// Add a handler at `POST /{resource_name}`. pub fn create(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = self.index_create_path(); @@ -76,7 +74,7 @@ where /// Add a handler at `GET /{resource_name}/new`. pub fn new(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = format!("/{}/new", self.name); @@ -86,7 +84,7 @@ where /// Add a handler at `GET /{resource_name}/:{resource_name}_id`. pub fn show(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = self.show_update_destroy_path(); @@ -96,7 +94,7 @@ where /// Add a handler at `GET /{resource_name}/:{resource_name}_id/edit`. pub fn edit(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = format!("/{0}/:{0}_id/edit", self.name); @@ -106,7 +104,7 @@ where /// Add a handler at `PUT or PATCH /resource_name/:{resource_name}_id`. pub fn update(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = self.show_update_destroy_path(); @@ -116,7 +114,7 @@ where /// Add a handler at `DELETE /{resource_name}/:{resource_name}_id`. pub fn destroy(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { let path = self.show_update_destroy_path(); @@ -131,14 +129,14 @@ where format!("/{0}/:{0}_id", self.name) } - fn route(mut self, path: &str, method_router: MethodRouter) -> Self { + fn route(mut self, path: &str, method_router: MethodRouter) -> Self { self.router = self.router.route(path, method_router); self } } -impl From> for Router { - fn from(resource: Resource) -> Self { +impl From> for Router { + fn from(resource: Resource) -> Self { resource.router } } @@ -147,9 +145,9 @@ impl From> for Router { mod tests { #[allow(unused_imports)] use super::*; - use axum::{extract::Path, http::Method, Router}; + use axum::{body::Body, extract::Path, http::Method, Router}; use http::Request; - use tower::{Service, ServiceExt}; + use tower::ServiceExt; #[tokio::test] async fn works() { @@ -207,10 +205,8 @@ mod tests { async fn call_route(app: &mut Router, method: Method, uri: &str) -> String { let res = app - .ready() - .await - .unwrap() - .call( + .clone() + .oneshot( Request::builder() .method(method) .uri(uri) diff --git a/axum-extra/src/routing/spa.rs b/axum-extra/src/routing/spa.rs index ad8d8af135..25265b02b3 100644 --- a/axum-extra/src/routing/spa.rs +++ b/axum-extra/src/routing/spa.rs @@ -1,5 +1,5 @@ use axum::{ - body::{Body, HttpBody}, + body::Body, error_handling::HandleError, response::IntoResponse, routing::{get_service, Route}, @@ -50,10 +50,10 @@ use tower_service::Service; /// - `GET /some/other/path` will serve `index.html` since there isn't another /// route for it /// - `GET /api/foo` will serve the `api_foo` handler function -pub struct SpaRouter Ready> { +pub struct SpaRouter Ready> { paths: Arc, handle_error: F, - _marker: PhantomData (S, B, T)>, + _marker: PhantomData (S, T)>, } #[derive(Debug)] @@ -63,7 +63,7 @@ struct Paths { index_file: PathBuf, } -impl SpaRouter Ready> { +impl SpaRouter Ready> { /// Create a new `SpaRouter`. /// /// Assets will be served at `GET /{serve_assets_at}` from the directory at `assets_dir`. @@ -86,7 +86,7 @@ impl SpaRouter Ready> { } } -impl SpaRouter { +impl SpaRouter { /// Set the path to the index file. /// /// `path` must be relative to `assets_dir` passed to [`SpaRouter::new`]. @@ -138,7 +138,7 @@ impl SpaRouter { /// let app = Router::new().merge(spa); /// # let _: Router = app; /// ``` - pub fn handle_error(self, f: F2) -> SpaRouter { + pub fn handle_error(self, f: F2) -> SpaRouter { SpaRouter { paths: self.paths, handle_error: f, @@ -147,17 +147,16 @@ impl SpaRouter { } } -impl From> for Router +impl From> for Router where F: Clone + Send + Sync + 'static, - HandleError, F, T>: Service, Error = Infallible>, - , F, T> as Service>>::Response: IntoResponse + Send, - , F, T> as Service>>::Future: Send, - B: HttpBody + Send + 'static, + HandleError, F, T>: Service, Error = Infallible>, + , F, T> as Service>>::Response: IntoResponse + Send, + , F, T> as Service>>::Future: Send, T: 'static, S: Clone + Send + Sync + 'static, { - fn from(spa: SpaRouter) -> Router { + fn from(spa: SpaRouter) -> Router { let assets_service = get_service(ServeDir::new(&spa.paths.assets_dir)) .handle_error(spa.handle_error.clone()); @@ -169,7 +168,7 @@ where } } -impl fmt::Debug for SpaRouter { +impl fmt::Debug for SpaRouter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { paths, @@ -180,7 +179,6 @@ impl fmt::Debug for SpaRouter { f.debug_struct("SpaRouter") .field("paths", &paths) .field("handle_error", &format_args!("{}", type_name::())) - .field("request_body_type", &format_args!("{}", type_name::())) .field( "extractor_input_type", &format_args!("{}", type_name::()), @@ -189,7 +187,7 @@ impl fmt::Debug for SpaRouter { } } -impl Clone for SpaRouter +impl Clone for SpaRouter where F: Clone, { @@ -265,7 +263,7 @@ mod tests { let spa = SpaRouter::new("/assets", "test_files").handle_error(handle_error); - Router::<(), Body>::new().merge(spa); + Router::<()>::new().merge(spa); } #[allow(dead_code)]