Skip to content

Commit

Permalink
chore(router): Update to axum 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Dec 18, 2024
1 parent f6f71fd commit dc9d893
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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-rc.1", default-features = false, optional = true}

# rustls
rustls-native-certs = { version = "0.8", optional = true }
Expand Down
23 changes: 19 additions & 4 deletions tonic/src/service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ impl RoutesBuilder {
/// Add a new service.
pub fn add_service<S>(&mut self, svc: S) -> &mut Self
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Response: axum::response::IntoResponse,
S::Future: Send + 'static,
{
Expand All @@ -52,7 +57,12 @@ impl Routes {
/// Create a new routes with `svc` already added to it.
pub fn new<S>(svc: S) -> Self
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Response: axum::response::IntoResponse,
S::Future: Send + 'static,
{
Expand All @@ -67,12 +77,17 @@ impl Routes {
/// Add a new service.
pub fn add_service<S>(mut self, svc: S) -> Self
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, 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<axum::body::Body>| req.map(Body::new)),
);
self
Expand Down
2 changes: 1 addition & 1 deletion tonic/src/transport/server/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl TcpIncoming {
/// # fn main() { } // Cannot have type parameters, hence instead define:
/// # fn run<S>(some_service: S) -> Result<(), Box<dyn Error + Send + Sync>>
/// # where
/// # S: Service<Request<Body>, Response = Response<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
/// # S: Service<Request<Body>, Response = Response<Body>, Error = Infallible> + NamedService + Clone + Send + Sync + 'static,
/// # S::Future: Send + 'static,
/// # {
/// // Find a free port
Expand Down
28 changes: 24 additions & 4 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ impl<L> Server<L> {
/// route around different services.
pub fn add_service<S>(&mut self, svc: S) -> Router<L>
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Response: axum::response::IntoResponse,
S::Future: Send + 'static,
L: Clone,
Expand All @@ -413,7 +418,12 @@ impl<L> Server<L> {
/// As a result, one cannot use this to toggle between two identically named implementations.
pub fn add_optional_service<S>(&mut self, svc: Option<S>) -> Router<L>
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Response: axum::response::IntoResponse,
S::Future: Send + 'static,
L: Clone,
Expand Down Expand Up @@ -726,7 +736,12 @@ impl<L> Router<L> {
/// Add a new service to this router.
pub fn add_service<S>(mut self, svc: S) -> Self
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Response: axum::response::IntoResponse,
S::Future: Send + 'static,
{
Expand All @@ -741,7 +756,12 @@ impl<L> Router<L> {
/// As a result, one cannot use this to toggle between two identically named implementations.
pub fn add_optional_service<S>(mut self, svc: Option<S>) -> Self
where
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + 'static,
S: Service<Request<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Response: axum::response::IntoResponse,
S::Future: Send + 'static,
{
Expand Down

0 comments on commit dc9d893

Please sign in to comment.