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

fix(build): allow services to be named Service #709

Merged
merged 1 commit into from
Jul 12, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
# Tests
"tests/included_service",
"tests/same_name",
"tests/service_named_service",
"tests/wellknown",
"tests/wellknown-compiled",
"tests/extern_path/uuid",
Expand Down
16 changes: 16 additions & 0 deletions tests/service_named_service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "service_named_service"
version = "0.1.0"
authors = ["Lucio Franco <luciofranco14@gmail.com>"]
edition = "2018"
publish = false
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tonic = { path = "../../tonic" }
prost = "0.8"

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
3 changes: 3 additions & 0 deletions tests/service_named_service/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/foo.proto").unwrap();
}
11 changes: 11 additions & 0 deletions tests/service_named_service/proto/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package foo;

service Service {
rpc Foo(stream FooRequest) returns (stream FooResponse) {}
}

message FooRequest {}

message FooResponse {}
3 changes: 3 additions & 0 deletions tests/service_named_service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("foo");
}
4 changes: 2 additions & 2 deletions tonic-build/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ pub fn generate<T: Service>(
pub fn with_interceptor<F>(inner: T, interceptor: F) -> #service_ident<InterceptedService<T, F>>
where
F: FnMut(tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status>,
T: Service<
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody>
>,
<T as Service<http::Request<tonic::body::BoxBody>>>::Error: Into<StdError> + Send + Sync,
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error: Into<StdError> + Send + Sync,
{
#service_ident::new(InterceptedService::new(inner, interceptor))
}
Expand Down
2 changes: 1 addition & 1 deletion tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn generate<T: Service>(
#configure_compression_methods
}

impl<T, B> Service<http::Request<B>> for #server_service<T>
impl<T, B> tonic::codegen::Service<http::Request<B>> for #server_service<T>
where
T: #server_trait,
B: Body + Send + Sync + 'static,
Expand Down