From ea06a1bb30bc325c7f6d7763fe48bf8b88c1c3ed Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Wed, 2 Aug 2023 11:23:29 -0400 Subject: [PATCH] feat(transport): Add `Router::into_router` (#1442) This adds `into_router` to tonic's `Router` that will convert it into an `axum::Router`. --- tonic/src/transport/server/mod.rs | 5 +++++ tonic/src/transport/service/router.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index df57d986b..0ac79853c 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -571,6 +571,11 @@ impl Router { self } + /// Convert this tonic `Router` into an axum `Router` consuming the tonic one. + pub fn into_router(self) -> axum::Router { + self.routes.into_router() + } + /// Consume this [`Server`] creating a future that will execute the server /// on [tokio]'s default executor. /// diff --git a/tonic/src/transport/service/router.rs b/tonic/src/transport/service/router.rs index dd4071592..328d59fe7 100644 --- a/tonic/src/transport/service/router.rs +++ b/tonic/src/transport/service/router.rs @@ -60,6 +60,11 @@ impl Routes { router: self.router.with_state(()), } } + + /// Convert this `Routes` into an [`axum::Router`]. + pub fn into_router(self) -> axum::Router { + self.router + } } async fn unimplemented() -> impl axum::response::IntoResponse {