Skip to content

Commit 08aa8fe

Browse files
committed
feat(transport): Add router feature
1 parent 07e4ee1 commit 08aa8fe

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

tonic/Cargo.toml

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ tls = ["dep:rustls-pemfile", "transport", "dep:tokio-rustls", "dep:rustls", "tok
3232
tls-roots = ["tls-roots-common", "dep:rustls-native-certs"]
3333
tls-roots-common = ["tls"]
3434
tls-webpki-roots = ["tls-roots-common", "dep:webpki-roots"]
35+
router = ["hyper", "dep:axum", "tower"]
3536
transport = [
36-
"dep:async-stream",
37-
"dep:axum",
37+
"router",
3838
"channel",
39+
"dep:async-stream",
3940
"dep:h2",
40-
"dep:hyper",
41+
"hyper/full",
4142
"tokio/net",
4243
"tokio/time",
43-
"dep:tower",
44+
"tower/balance", "tower/buffer", "tower/discover", "tower/limit", "tower/load", "tower/make", "tower/timeout", "tower/util",
4445
"dep:hyper-timeout",
4546
]
4647
channel = []
@@ -70,10 +71,10 @@ async-trait = {version = "0.1.13", optional = true}
7071

7172
# transport
7273
h2 = {version = "0.3.17", optional = true}
73-
hyper = {version = "0.14.26", features = ["full"], optional = true}
74+
hyper = {version = "0.14.26", optional = true}
7475
hyper-timeout = {version = "0.4", optional = true}
7576
tokio-stream = "0.1"
76-
tower = {version = "0.4.7", default-features = false, features = ["balance", "buffer", "discover", "limit", "load", "make", "timeout", "util"], optional = true}
77+
tower = {version = "0.4.7", default-features = false, optional = true}
7778
axum = {version = "0.6.9", default_features = false, optional = true}
7879

7980
# rustls

tonic/src/service/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! Utilities for using Tower services with Tonic.
22
33
pub mod interceptor;
4+
#[cfg(feature = "router")]
5+
mod router;
46

57
#[doc(inline)]
68
pub use self::interceptor::{interceptor, Interceptor};
9+
#[doc(inline)]
10+
#[cfg(feature = "router")]
11+
pub use self::router::{Routes, RoutesBuilder};

tonic/src/transport/service/router.rs renamed to tonic/src/service/router.rs

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl Routes {
8383
self
8484
}
8585

86+
#[cfg(feature = "transport")]
8687
pub(crate) fn prepare(self) -> Self {
8788
Self {
8889
// this makes axum perform update some internals of the router that improves perf

tonic/src/transport/server/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ mod tls;
99
#[cfg(unix)]
1010
mod unix;
1111

12-
pub use super::service::Routes;
13-
pub use super::service::RoutesBuilder;
12+
/// A deprecated re-export. Please use `tonic::service::{Routes, RoutesBuilder}` directly.
13+
pub use super::service::{Routes, RoutesBuilder};
1414

1515
#[doc(inline)]
1616
/// A deprecated re-export. Please use `tonic::server::NamedService` directly.

tonic/src/transport/service/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub(crate) mod executor;
66
pub(crate) mod grpc_timeout;
77
mod io;
88
mod reconnect;
9-
mod router;
109
#[cfg(feature = "tls")]
1110
mod tls;
1211
mod user_agent;
@@ -22,5 +21,5 @@ pub(crate) use self::io::ServerIo;
2221
pub(crate) use self::tls::{TlsAcceptor, TlsConnector};
2322
pub(crate) use self::user_agent::UserAgent;
2423

25-
pub use self::router::Routes;
26-
pub use self::router::RoutesBuilder;
24+
/// A deprecated re-export. Please use `tonic::service::{Routes, RoutesBuilder}` directly.
25+
pub use crate::service::{Routes, RoutesBuilder};

0 commit comments

Comments
 (0)