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 1, 2024
1 parent 191ec8c commit 0e32b36
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
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
4 changes: 4 additions & 0 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ impl<L> Server<L> {
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Future: Send + 'static,
L: Clone,
Expand All @@ -420,6 +421,7 @@ impl<L> Server<L> {
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Future: Send + 'static,
L: Clone,
Expand Down Expand Up @@ -736,6 +738,7 @@ impl<L> Router<L> {
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Future: Send + 'static,
{
Expand All @@ -754,6 +757,7 @@ impl<L> Router<L> {
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Future: Send + 'static,
{
Expand Down

0 comments on commit 0e32b36

Please sign in to comment.