Skip to content

Commit e17ecb5

Browse files
authored
chore(interceptor): Rename f with interceptor (#2000)
1 parent 1359d7a commit e17ecb5

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

tonic/src/service/interceptor.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,69 +55,72 @@ where
5555
/// Create a new interceptor layer.
5656
///
5757
/// See [`Interceptor`] for more details.
58-
pub fn interceptor<F>(f: F) -> InterceptorLayer<F>
58+
pub fn interceptor<I>(interceptor: I) -> InterceptorLayer<I>
5959
where
60-
F: Interceptor,
60+
I: Interceptor,
6161
{
62-
InterceptorLayer { f }
62+
InterceptorLayer { interceptor }
6363
}
6464

6565
/// A gRPC interceptor that can be used as a [`Layer`],
6666
/// created by calling [`interceptor`].
6767
///
6868
/// See [`Interceptor`] for more details.
6969
#[derive(Debug, Clone, Copy)]
70-
pub struct InterceptorLayer<F> {
71-
f: F,
70+
pub struct InterceptorLayer<I> {
71+
interceptor: I,
7272
}
7373

74-
impl<S, F> Layer<S> for InterceptorLayer<F>
74+
impl<S, I> Layer<S> for InterceptorLayer<I>
7575
where
76-
F: Interceptor + Clone,
76+
I: Interceptor + Clone,
7777
{
78-
type Service = InterceptedService<S, F>;
78+
type Service = InterceptedService<S, I>;
7979

8080
fn layer(&self, service: S) -> Self::Service {
81-
InterceptedService::new(service, self.f.clone())
81+
InterceptedService::new(service, self.interceptor.clone())
8282
}
8383
}
8484

8585
/// A service wrapped in an interceptor middleware.
8686
///
8787
/// See [`Interceptor`] for more details.
8888
#[derive(Clone, Copy)]
89-
pub struct InterceptedService<S, F> {
89+
pub struct InterceptedService<S, I> {
9090
inner: S,
91-
f: F,
91+
interceptor: I,
9292
}
9393

94-
impl<S, F> InterceptedService<S, F> {
94+
impl<S, I> InterceptedService<S, I> {
9595
/// Create a new `InterceptedService` that wraps `S` and intercepts each request with the
9696
/// function `F`.
97-
pub fn new(service: S, f: F) -> Self
97+
pub fn new(service: S, interceptor: I) -> Self
9898
where
99-
F: Interceptor,
99+
I: Interceptor,
100100
{
101-
Self { inner: service, f }
101+
Self {
102+
inner: service,
103+
interceptor,
104+
}
102105
}
103106
}
104107

105-
impl<S, F> fmt::Debug for InterceptedService<S, F>
108+
impl<S, I> fmt::Debug for InterceptedService<S, I>
106109
where
107110
S: fmt::Debug,
108111
{
109112
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110113
f.debug_struct("InterceptedService")
111114
.field("inner", &self.inner)
112-
.field("f", &format_args!("{}", std::any::type_name::<F>()))
115+
.field("f", &format_args!("{}", std::any::type_name::<I>()))
113116
.finish()
114117
}
115118
}
116119

117-
impl<S, F, ReqBody, ResBody> Service<http::Request<ReqBody>> for InterceptedService<S, F>
120+
impl<S, I, ReqBody, ResBody> Service<http::Request<ReqBody>> for InterceptedService<S, I>
118121
where
119122
S: Service<http::Request<ReqBody>, Response = http::Response<ResBody>>,
120-
F: Interceptor,
123+
I: Interceptor,
121124
ResBody: Default,
122125
{
123126
type Response = http::Response<ResBody>;
@@ -142,7 +145,7 @@ where
142145
let (metadata, extensions, msg) = req.into_parts();
143146

144147
match self
145-
.f
148+
.interceptor
146149
.call(crate::Request::from_parts(metadata, extensions, ()))
147150
{
148151
Ok(req) => {
@@ -157,7 +160,7 @@ where
157160
}
158161

159162
// required to use `InterceptedService` with `Router`
160-
impl<S, F> crate::server::NamedService for InterceptedService<S, F>
163+
impl<S, I> crate::server::NamedService for InterceptedService<S, I>
161164
where
162165
S: crate::server::NamedService,
163166
{

0 commit comments

Comments
 (0)