From ef37241b9fb53ecf7a7d060c6c19b35e2e62e23f Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 5 Oct 2024 19:16:11 +0900 Subject: [PATCH] chore(router): Update to axum 0.8 --- tonic/Cargo.toml | 2 +- tonic/src/service/router.rs | 23 +++++++++++++++++++---- tonic/src/transport/server/incoming.rs | 2 +- tonic/src/transport/server/mod.rs | 4 ++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 2e0ede0f5..4e2ed7d8e 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -88,7 +88,7 @@ hyper-util = { version = "0.1.4", features = ["tokio"], optional = true } socket2 = { version = "0.5", optional = true, features = ["all"] } tokio = {version = "1", default-features = false, optional = true} tower = {version = "0.5", default-features = false, optional = true} -axum = {version = "0.7", default-features = false, optional = true} +axum = {version = "=0.8.0-alpha.1", default-features = false, optional = true} # rustls rustls-pki-types = { version = "1.9", features = ["std"], optional = true } diff --git a/tonic/src/service/router.rs b/tonic/src/service/router.rs index c059e908a..d60a0e924 100644 --- a/tonic/src/service/router.rs +++ b/tonic/src/service/router.rs @@ -30,7 +30,12 @@ impl RoutesBuilder { /// Add a new service. pub fn add_service(&mut self, svc: S) -> &mut Self where - S: Service, Error = Infallible> + NamedService + Clone + Send + 'static, + S: Service, Error = Infallible> + + NamedService + + Clone + + Send + + Sync + + 'static, S::Response: axum::response::IntoResponse, S::Future: Send + 'static, { @@ -57,7 +62,12 @@ impl Routes { /// Create a new routes with `svc` already added to it. pub fn new(svc: S) -> Self where - S: Service, Error = Infallible> + NamedService + Clone + Send + 'static, + S: Service, Error = Infallible> + + NamedService + + Clone + + Send + + Sync + + 'static, S::Response: axum::response::IntoResponse, S::Future: Send + 'static, { @@ -72,12 +82,17 @@ impl Routes { /// Add a new service. pub fn add_service(mut self, svc: S) -> Self where - S: Service, Error = Infallible> + NamedService + Clone + Send + 'static, + S: Service, Error = Infallible> + + NamedService + + Clone + + Send + + Sync + + 'static, S::Response: axum::response::IntoResponse, S::Future: Send + 'static, { self.router = self.router.route_service( - &format!("/{}/*rest", S::NAME), + &format!("/{}/{{*rest}}", S::NAME), svc.map_request(|req: Request| req.map(boxed)), ); self diff --git a/tonic/src/transport/server/incoming.rs b/tonic/src/transport/server/incoming.rs index 50ee5da0e..56e4bea55 100644 --- a/tonic/src/transport/server/incoming.rs +++ b/tonic/src/transport/server/incoming.rs @@ -182,7 +182,7 @@ impl TcpIncoming { /// # fn main() { } // Cannot have type parameters, hence instead define: /// # fn run(some_service: S) -> Result<(), Box> /// # where - /// # S: Service, Response = Response, Error = Infallible> + NamedService + Clone + Send + 'static, + /// # S: Service, Response = Response, Error = Infallible> + NamedService + Clone + Send + Sync + 'static, /// # S::Future: Send + 'static, /// # { /// // Find a free port diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index b419ad81d..ea28b938d 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -399,6 +399,7 @@ impl Server { + NamedService + Clone + Send + + Sync + 'static, S::Future: Send + 'static, L: Clone, @@ -420,6 +421,7 @@ impl Server { + NamedService + Clone + Send + + Sync + 'static, S::Future: Send + 'static, L: Clone, @@ -737,6 +739,7 @@ impl Router { + NamedService + Clone + Send + + Sync + 'static, S::Future: Send + 'static, { @@ -756,6 +759,7 @@ impl Router { + NamedService + Clone + Send + + Sync + 'static, S::Future: Send + 'static, {