From 276a950b67b43757f37c36a17b4700f00036599a Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Wed, 29 Jun 2022 22:20:12 +0200 Subject: [PATCH] Only accept `Router` in `Resource::{nest, nest_collection}` --- axum-extra/src/routing/resource.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/axum-extra/src/routing/resource.rs b/axum-extra/src/routing/resource.rs index af870b2b..482571f1 100644 --- a/axum-extra/src/routing/resource.rs +++ b/axum-extra/src/routing/resource.rs @@ -140,26 +140,18 @@ where /// Nest another route at the "member level". /// /// The routes will be nested at `/{resource_name}/:{resource_name}_id`. - pub fn nest(mut self, svc: T) -> Self - where - T: Service, Response = Response, Error = Infallible> + Clone + Send + 'static, - T::Future: Send + 'static, - { + pub fn nest(mut self, router: Router) -> Self { let path = self.show_update_destroy_path(); - self.router = self.router.nest_service(&path, svc); + self.router = self.router.nest(&path, router); self } /// Nest another route at the "collection level". /// /// The routes will be nested at `/{resource_name}`. - pub fn nest_collection(mut self, svc: T) -> Self - where - T: Service, Response = Response, Error = Infallible> + Clone + Send + 'static, - T::Future: Send + 'static, - { + pub fn nest_collection(mut self, router: Router) -> Self { let path = self.index_create_path(); - self.router = self.router.nest_service(&path, svc); + self.router = self.router.nest(&path, router); self } @@ -204,7 +196,6 @@ mod tests { .edit(|Path(id): Path| async move { format!("users#edit id={}", id) }) .update(|Path(id): Path| async move { format!("users#update id={}", id) }) .destroy(|Path(id): Path| async move { format!("users#destroy id={}", id) }) - // TODO(david): figure out if we need `nest_service` + `nest` methods on `Resource` .nest(Router::new().route( "/tweets", get(|Path(id): Path| async move { format!("users#tweets id={}", id) }),