Skip to content

Commit dc9d893

Browse files
committed
chore(router): Update to axum 0.8
1 parent f6f71fd commit dc9d893

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

tonic/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ hyper-util = { version = "0.1.4", features = ["tokio"], optional = true }
8484
socket2 = { version = "0.5", optional = true, features = ["all"] }
8585
tokio = {version = "1", default-features = false, optional = true}
8686
tower = {version = "0.5", default-features = false, optional = true}
87-
axum = {version = "0.7", default-features = false, optional = true}
87+
axum = {version = "=0.8.0-rc.1", default-features = false, optional = true}
8888

8989
# rustls
9090
rustls-native-certs = { version = "0.8", optional = true }

tonic/src/service/router.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ impl RoutesBuilder {
2525
/// Add a new service.
2626
pub fn add_service<S>(&mut self, svc: S) -> &mut Self
2727
where
28-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
28+
S: Service<Request<Body>, Error = Infallible>
29+
+ NamedService
30+
+ Clone
31+
+ Send
32+
+ Sync
33+
+ 'static,
2934
S::Response: axum::response::IntoResponse,
3035
S::Future: Send + 'static,
3136
{
@@ -52,7 +57,12 @@ impl Routes {
5257
/// Create a new routes with `svc` already added to it.
5358
pub fn new<S>(svc: S) -> Self
5459
where
55-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
60+
S: Service<Request<Body>, Error = Infallible>
61+
+ NamedService
62+
+ Clone
63+
+ Send
64+
+ Sync
65+
+ 'static,
5666
S::Response: axum::response::IntoResponse,
5767
S::Future: Send + 'static,
5868
{
@@ -67,12 +77,17 @@ impl Routes {
6777
/// Add a new service.
6878
pub fn add_service<S>(mut self, svc: S) -> Self
6979
where
70-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
80+
S: Service<Request<Body>, Error = Infallible>
81+
+ NamedService
82+
+ Clone
83+
+ Send
84+
+ Sync
85+
+ 'static,
7186
S::Response: axum::response::IntoResponse,
7287
S::Future: Send + 'static,
7388
{
7489
self.router = self.router.route_service(
75-
&format!("/{}/*rest", S::NAME),
90+
&format!("/{}/{{*rest}}", S::NAME),
7691
svc.map_request(|req: Request<axum::body::Body>| req.map(Body::new)),
7792
);
7893
self

tonic/src/transport/server/incoming.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl TcpIncoming {
3636
/// # fn main() { } // Cannot have type parameters, hence instead define:
3737
/// # fn run<S>(some_service: S) -> Result<(), Box<dyn Error + Send + Sync>>
3838
/// # where
39-
/// # S: Service<Request<Body>, Response = Response<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
39+
/// # S: Service<Request<Body>, Response = Response<Body>, Error = Infallible> + NamedService + Clone + Send + Sync + 'static,
4040
/// # S::Future: Send + 'static,
4141
/// # {
4242
/// // Find a free port

tonic/src/transport/server/mod.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,12 @@ impl<L> Server<L> {
395395
/// route around different services.
396396
pub fn add_service<S>(&mut self, svc: S) -> Router<L>
397397
where
398-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
398+
S: Service<Request<Body>, Error = Infallible>
399+
+ NamedService
400+
+ Clone
401+
+ Send
402+
+ Sync
403+
+ 'static,
399404
S::Response: axum::response::IntoResponse,
400405
S::Future: Send + 'static,
401406
L: Clone,
@@ -413,7 +418,12 @@ impl<L> Server<L> {
413418
/// As a result, one cannot use this to toggle between two identically named implementations.
414419
pub fn add_optional_service<S>(&mut self, svc: Option<S>) -> Router<L>
415420
where
416-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
421+
S: Service<Request<Body>, Error = Infallible>
422+
+ NamedService
423+
+ Clone
424+
+ Send
425+
+ Sync
426+
+ 'static,
417427
S::Response: axum::response::IntoResponse,
418428
S::Future: Send + 'static,
419429
L: Clone,
@@ -726,7 +736,12 @@ impl<L> Router<L> {
726736
/// Add a new service to this router.
727737
pub fn add_service<S>(mut self, svc: S) -> Self
728738
where
729-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
739+
S: Service<Request<Body>, Error = Infallible>
740+
+ NamedService
741+
+ Clone
742+
+ Send
743+
+ Sync
744+
+ 'static,
730745
S::Response: axum::response::IntoResponse,
731746
S::Future: Send + 'static,
732747
{
@@ -741,7 +756,12 @@ impl<L> Router<L> {
741756
/// As a result, one cannot use this to toggle between two identically named implementations.
742757
pub fn add_optional_service<S>(mut self, svc: Option<S>) -> Self
743758
where
744-
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
759+
S: Service<Request<Body>, Error = Infallible>
760+
+ NamedService
761+
+ Clone
762+
+ Send
763+
+ Sync
764+
+ 'static,
745765
S::Response: axum::response::IntoResponse,
746766
S::Future: Send + 'static,
747767
{

0 commit comments

Comments
 (0)