Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(interceptor): Change InterceptorLayer constructor associated function #2005

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/src/tower/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let channel = ServiceBuilder::new()
// Interceptors can be also be applied as middleware
.layer(tonic::service::interceptor(intercept))
.layer(tonic::service::InterceptorLayer::new(intercept))
.layer_fn(AuthSvc::new)
.service(channel);

Expand Down
2 changes: 1 addition & 1 deletion examples/src/tower/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Apply our own middleware
.layer(MyMiddlewareLayer::default())
// Interceptors can be also be applied as middleware
.layer(tonic::service::interceptor(intercept))
.layer(tonic::service::InterceptorLayer::new(intercept))
.into_inner();

Server::builder()
Expand Down
10 changes: 10 additions & 0 deletions tonic/src/service/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ where
/// Create a new interceptor layer.
///
/// See [`Interceptor`] for more details.
#[deprecated(since = "0.12.4", note = "use `InterceptorLayer::new()` instead")]
pub fn interceptor<I>(interceptor: I) -> InterceptorLayer<I>
where
I: Interceptor,
Expand All @@ -71,6 +72,15 @@ pub struct InterceptorLayer<I> {
interceptor: I,
}

impl<I> InterceptorLayer<I> {
/// Create a new interceptor layer.
///
/// See [`Interceptor`] for more details.
pub fn new(interceptor: I) -> Self {
Self { interceptor }
}
}

impl<S, I> Layer<S> for InterceptorLayer<I>
where
I: Clone,
Expand Down
5 changes: 4 additions & 1 deletion tonic/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ pub(crate) mod layered;
pub(crate) mod router;

#[doc(inline)]
pub use self::interceptor::{interceptor, Interceptor};
#[allow(deprecated)]
pub use self::interceptor::interceptor;
#[doc(inline)]
pub use self::interceptor::{Interceptor, InterceptorLayer};
pub use self::layered::{LayerExt, Layered};
#[doc(inline)]
#[cfg(feature = "router")]
Expand Down