Skip to content

Commit 28cd1e9

Browse files
committed
feat: Make Layered constructor associated function
1 parent 96e5dfe commit 28cd1e9

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

examples/src/grpc-web/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3333
let addr = "127.0.0.1:3000".parse().unwrap();
3434

3535
let greeter = MyGreeter::default();
36-
let greeter = tonic::service::layered_service(
36+
let greeter = tonic::service::Layered::new(
3737
tonic_web::GrpcWebLayer::new().layer(GreeterServer::new(greeter)),
3838
tower_http::cors::CorsLayer::default(),
3939
);

tonic/src/service/layered.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ use crate::server::NamedService;
1010

1111
/// A layered service to propagate [`NamedService`] implementation.
1212
#[derive(Debug, Clone)]
13-
pub struct Layered<S, T> {
13+
pub struct Layered<S, T, L> {
1414
inner: S,
15-
_ty: PhantomData<T>,
15+
_ty_s: PhantomData<T>,
16+
_ty_l: PhantomData<L>,
1617
}
1718

18-
/// Create a new service from the service and the layer.
19-
pub fn layered_service<S, L>(service: S, layer: L) -> Layered<L::Service, S>
19+
impl<S, L> Layered<L::Service, S, L>
2020
where
2121
L: Layer<S>,
2222
{
23-
Layered {
24-
inner: layer.layer(service),
25-
_ty: PhantomData,
23+
/// Create a new service from the service and the layer.
24+
pub fn new(service: S, layer: L) -> Layered<L::Service, S, L> {
25+
Layered {
26+
inner: layer.layer(service),
27+
_ty_s: PhantomData,
28+
_ty_l: PhantomData,
29+
}
2630
}
2731
}
2832

29-
impl<S, T: NamedService> NamedService for Layered<S, T> {
33+
impl<S, T: NamedService, L> NamedService for Layered<S, T, L> {
3034
const NAME: &'static str = T::NAME;
3135
}
3236

33-
impl<Req, S, T> Service<Req> for Layered<S, T>
37+
impl<Req, S, T, L> Service<Req> for Layered<S, T, L>
3438
where
3539
S: Service<Req>,
3640
{

tonic/src/service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) mod router;
77

88
#[doc(inline)]
99
pub use self::interceptor::{interceptor, Interceptor};
10-
pub use self::layered::{layered_service, Layered};
10+
pub use self::layered::Layered;
1111
#[doc(inline)]
1212
#[cfg(feature = "router")]
1313
pub use self::router::{Routes, RoutesBuilder};

0 commit comments

Comments
 (0)