From 928a37810579ba4dff5fbd7789dc946e9a5016c3 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 e45aeb9b0..6c19eae55 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -86,7 +86,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 17b4423dd..9c6fade35 100644 --- a/tonic/src/service/router.rs +++ b/tonic/src/service/router.rs @@ -25,7 +25,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, { @@ -52,7 +57,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, { @@ -67,12 +77,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(Body::new)), ); self diff --git a/tonic/src/transport/server/incoming.rs b/tonic/src/transport/server/incoming.rs index a3ff0da07..3b99a98bc 100644 --- a/tonic/src/transport/server/incoming.rs +++ b/tonic/src/transport/server/incoming.rs @@ -36,7 +36,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 77bf00710..ef4d1463d 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, @@ -736,6 +738,7 @@ impl Router { + NamedService + Clone + Send + + Sync + 'static, S::Future: Send + 'static, { @@ -754,6 +757,7 @@ impl Router { + NamedService + Clone + Send + + Sync + 'static, S::Future: Send + 'static, {