Skip to content

Commit 380d81d

Browse files
authored
fix(build): allow services to be named Service (#709)
Fixes #676
1 parent 167e8cb commit 380d81d

File tree

7 files changed

+37
-3
lines changed

7 files changed

+37
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
# Tests
1515
"tests/included_service",
1616
"tests/same_name",
17+
"tests/service_named_service",
1718
"tests/wellknown",
1819
"tests/wellknown-compiled",
1920
"tests/extern_path/uuid",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "service_named_service"
3+
version = "0.1.0"
4+
authors = ["Lucio Franco <luciofranco14@gmail.com>"]
5+
edition = "2018"
6+
publish = false
7+
license = "MIT"
8+
9+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
11+
[dependencies]
12+
tonic = { path = "../../tonic" }
13+
prost = "0.8"
14+
15+
[build-dependencies]
16+
tonic-build = { path = "../../tonic-build" }

tests/service_named_service/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
tonic_build::compile_protos("proto/foo.proto").unwrap();
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
package foo;
4+
5+
service Service {
6+
rpc Foo(stream FooRequest) returns (stream FooResponse) {}
7+
}
8+
9+
message FooRequest {}
10+
11+
message FooResponse {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod pb {
2+
tonic::include_proto!("foo");
3+
}

tonic-build/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ pub fn generate<T: Service>(
6969
pub fn with_interceptor<F>(inner: T, interceptor: F) -> #service_ident<InterceptedService<T, F>>
7070
where
7171
F: FnMut(tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status>,
72-
T: Service<
72+
T: tonic::codegen::Service<
7373
http::Request<tonic::body::BoxBody>,
7474
Response = http::Response<<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody>
7575
>,
76-
<T as Service<http::Request<tonic::body::BoxBody>>>::Error: Into<StdError> + Send + Sync,
76+
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error: Into<StdError> + Send + Sync,
7777
{
7878
#service_ident::new(InterceptedService::new(inner, interceptor))
7979
}

tonic-build/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn generate<T: Service>(
112112
#configure_compression_methods
113113
}
114114

115-
impl<T, B> Service<http::Request<B>> for #server_service<T>
115+
impl<T, B> tonic::codegen::Service<http::Request<B>> for #server_service<T>
116116
where
117117
T: #server_trait,
118118
B: Body + Send + Sync + 'static,

0 commit comments

Comments
 (0)