diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 013cc6e72..3877325d6 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -32,15 +32,16 @@ tls = ["dep:rustls-pemfile", "transport", "dep:tokio-rustls", "dep:rustls", "tok tls-roots = ["tls-roots-common", "dep:rustls-native-certs"] tls-roots-common = ["tls"] tls-webpki-roots = ["tls-roots-common", "dep:webpki-roots"] +router = ["hyper", "dep:axum", "tower"] transport = [ - "dep:async-stream", - "dep:axum", + "router", "channel", + "dep:async-stream", "dep:h2", - "dep:hyper", + "hyper/full", "tokio/net", "tokio/time", - "dep:tower", + "tower/balance", "tower/buffer", "tower/discover", "tower/limit", "tower/load", "tower/make", "tower/timeout", "tower/util", "dep:hyper-timeout", ] channel = [] @@ -70,10 +71,10 @@ async-trait = {version = "0.1.13", optional = true} # transport h2 = {version = "0.3.17", optional = true} -hyper = {version = "0.14.26", features = ["full"], optional = true} +hyper = {version = "0.14.26", optional = true} hyper-timeout = {version = "0.4", optional = true} tokio-stream = "0.1" -tower = {version = "0.4.7", default-features = false, features = ["balance", "buffer", "discover", "limit", "load", "make", "timeout", "util"], optional = true} +tower = {version = "0.4.7", default-features = false, optional = true} axum = {version = "0.6.9", default_features = false, optional = true} # rustls diff --git a/tonic/src/service/mod.rs b/tonic/src/service/mod.rs index c9aad52be..d23f9cfee 100644 --- a/tonic/src/service/mod.rs +++ b/tonic/src/service/mod.rs @@ -1,6 +1,11 @@ //! Utilities for using Tower services with Tonic. pub mod interceptor; +#[cfg(feature = "router")] +mod router; #[doc(inline)] pub use self::interceptor::{interceptor, Interceptor}; +#[doc(inline)] +#[cfg(feature = "router")] +pub use self::router::{Routes, RoutesBuilder}; diff --git a/tonic/src/transport/service/router.rs b/tonic/src/service/router.rs similarity index 99% rename from tonic/src/transport/service/router.rs rename to tonic/src/service/router.rs index 85636c4d4..1aca4758b 100644 --- a/tonic/src/transport/service/router.rs +++ b/tonic/src/service/router.rs @@ -83,6 +83,7 @@ impl Routes { self } + #[cfg(feature = "transport")] pub(crate) fn prepare(self) -> Self { Self { // this makes axum perform update some internals of the router that improves perf diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index e10f11f68..28ef00a86 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -9,8 +9,8 @@ mod tls; #[cfg(unix)] mod unix; -pub use super::service::Routes; -pub use super::service::RoutesBuilder; +/// A deprecated re-export. Please use `tonic::service::{Routes, RoutesBuilder}` directly. +pub use super::service::{Routes, RoutesBuilder}; #[doc(inline)] /// A deprecated re-export. Please use `tonic::server::NamedService` directly. diff --git a/tonic/src/transport/service/mod.rs b/tonic/src/transport/service/mod.rs index 69d850f10..06ade78ac 100644 --- a/tonic/src/transport/service/mod.rs +++ b/tonic/src/transport/service/mod.rs @@ -6,7 +6,6 @@ pub(crate) mod executor; pub(crate) mod grpc_timeout; mod io; mod reconnect; -mod router; #[cfg(feature = "tls")] mod tls; mod user_agent; @@ -22,5 +21,5 @@ pub(crate) use self::io::ServerIo; pub(crate) use self::tls::{TlsAcceptor, TlsConnector}; pub(crate) use self::user_agent::UserAgent; -pub use self::router::Routes; -pub use self::router::RoutesBuilder; +/// A deprecated re-export. Please use `tonic::service::{Routes, RoutesBuilder}` directly. +pub use crate::service::{Routes, RoutesBuilder};