Skip to content

Commit

Permalink
feat(transport): Add Router::into_router (#1442)
Browse files Browse the repository at this point in the history
This adds `into_router` to tonic's `Router` that will convert it into an `axum::Router`.
  • Loading branch information
LucioFranco authored Aug 2, 2023
1 parent d44925b commit ea06a1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ impl<L> Router<L> {
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.
///
Expand Down
5 changes: 5 additions & 0 deletions tonic/src/transport/service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ea06a1b

Please sign in to comment.