Skip to content

Commit

Permalink
feat(transport): Make service router independent from transport
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Mar 1, 2024
1 parent 8a53392 commit 6847a34
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
13 changes: 7 additions & 6 deletions tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ tls = ["dep:rustls-pki-types", "dep:rustls-pemfile", "transport", "dep:tokio-rus
tls-roots = ["tls-roots-common", "dep:rustls-native-certs"]
tls-roots-common = ["tls"]
tls-webpki-roots = ["tls-roots-common", "dep:webpki-roots"]
router = ["dep:hyper", "dep:axum", "dep:tower"]
transport = [
"dep:async-stream",
"dep:axum",
"router",
"channel",
"dep:async-stream",
"dep:h2",
"dep:hyper",
"dep:hyper", "hyper?/full",
"dep:tokio", "tokio?/net", "tokio?/time",
"dep:tower",
"dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/limit", "tower?/load", "tower?/make", "tower?/timeout", "tower?/util",
"dep:hyper-timeout",
]
channel = []
Expand Down Expand Up @@ -68,11 +69,11 @@ async-trait = {version = "0.1.13", optional = true}

# transport
h2 = {version = "0.3.24", 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 = {version = "1.0.1", 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
Expand Down
5 changes: 5 additions & 0 deletions tonic/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

pub use conn::{Connected, TcpConnectInfo};
#[cfg(feature = "tls")]
Expand Down
5 changes: 2 additions & 3 deletions tonic/src/transport/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};

0 comments on commit 6847a34

Please sign in to comment.