From a562a3ce329a38696dfcb0d82b7102d93fb30a5c Mon Sep 17 00:00:00 2001 From: Shrutesh Pachineela Date: Wed, 21 Dec 2022 22:37:07 +0530 Subject: [PATCH] fix(build): Allow Services to be named Result (#1203) closes #1156 --- Cargo.toml | 1 + tests/service_named_result/Cargo.toml | 14 ++++++++++++++ tests/service_named_result/LICENSE | 19 +++++++++++++++++++ tests/service_named_result/build.rs | 3 +++ tests/service_named_result/proto/result.proto | 13 +++++++++++++ tests/service_named_result/src/lib.rs | 3 +++ tonic-build/src/client.rs | 8 ++++---- tonic-build/src/server.rs | 14 +++++++------- tonic-health/src/generated/grpc.health.v1.rs | 18 ++++++++++++------ .../src/generated/grpc.reflection.v1alpha.rs | 14 ++++++++++---- 10 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 tests/service_named_result/Cargo.toml create mode 100644 tests/service_named_result/LICENSE create mode 100644 tests/service_named_result/build.rs create mode 100644 tests/service_named_result/proto/result.proto create mode 100644 tests/service_named_result/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index eaa8d5334..1cedaeef5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,4 +22,5 @@ members = [ "tests/root-crate-path", "tests/compression", "tonic-web/tests/integration", + "tests/service_named_result", ] diff --git a/tests/service_named_result/Cargo.toml b/tests/service_named_result/Cargo.toml new file mode 100644 index 000000000..1730235e1 --- /dev/null +++ b/tests/service_named_result/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "service_named_result" +version = "0.1.0" +edition = "2021" +publish = false + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +prost = "0.11" +tonic = {path = "../../tonic"} + +[build-dependencies] +tonic-build = {path = "../../tonic-build"} diff --git a/tests/service_named_result/LICENSE b/tests/service_named_result/LICENSE new file mode 100644 index 000000000..307709840 --- /dev/null +++ b/tests/service_named_result/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2020 Lucio Franco + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/tests/service_named_result/build.rs b/tests/service_named_result/build.rs new file mode 100644 index 000000000..851e9f712 --- /dev/null +++ b/tests/service_named_result/build.rs @@ -0,0 +1,3 @@ +fn main() { + tonic_build::compile_protos("proto/result.proto").unwrap(); +} diff --git a/tests/service_named_result/proto/result.proto b/tests/service_named_result/proto/result.proto new file mode 100644 index 000000000..bd7d07130 --- /dev/null +++ b/tests/service_named_result/proto/result.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; + +package result; + +service Result { + rpc Listen(google.protobuf.Empty) returns (Reply) {} +} + +message Reply { + int32 step = 1; +} \ No newline at end of file diff --git a/tests/service_named_result/src/lib.rs b/tests/service_named_result/src/lib.rs new file mode 100644 index 000000000..db83bfc39 --- /dev/null +++ b/tests/service_named_result/src/lib.rs @@ -0,0 +1,3 @@ +pub mod pb { + tonic::include_proto!("result"); +} diff --git a/tonic-build/src/client.rs b/tonic-build/src/client.rs index 6eb4f608b..ae7861cc1 100644 --- a/tonic-build/src/client.rs +++ b/tonic-build/src/client.rs @@ -225,7 +225,7 @@ fn generate_unary( pub async fn #ident( &mut self, request: impl tonic::IntoRequest<#request>, - ) -> Result, tonic::Status> { + ) -> std::result::Result, tonic::Status> { self.inner.ready().await.map_err(|e| { tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) })?; @@ -251,7 +251,7 @@ fn generate_server_streaming( pub async fn #ident( &mut self, request: impl tonic::IntoRequest<#request>, - ) -> Result>, tonic::Status> { + ) -> std::result::Result>, tonic::Status> { self.inner.ready().await.map_err(|e| { tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) })?; @@ -277,7 +277,7 @@ fn generate_client_streaming( pub async fn #ident( &mut self, request: impl tonic::IntoStreamingRequest - ) -> Result, tonic::Status> { + ) -> std::result::Result, tonic::Status> { self.inner.ready().await.map_err(|e| { tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) })?; @@ -303,7 +303,7 @@ fn generate_streaming( pub async fn #ident( &mut self, request: impl tonic::IntoStreamingRequest - ) -> Result>, tonic::Status> { + ) -> std::result::Result>, tonic::Status> { self.inner.ready().await.map_err(|e| { tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) })?; diff --git a/tonic-build/src/server.rs b/tonic-build/src/server.rs index 22e1e245a..efaa70014 100644 --- a/tonic-build/src/server.rs +++ b/tonic-build/src/server.rs @@ -144,7 +144,7 @@ pub(crate) fn generate_internal( type Error = std::convert::Infallible; type Future = BoxFuture; - fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } @@ -251,14 +251,14 @@ fn generate_trait_methods( quote! { #method_doc async fn #name(&self, request: tonic::Request<#req_message>) - -> Result, tonic::Status>; + -> std::result::Result, tonic::Status>; } } (true, false) => { quote! { #method_doc async fn #name(&self, request: tonic::Request>) - -> Result, tonic::Status>; + -> std::result::Result, tonic::Status>; } } (false, true) => { @@ -270,11 +270,11 @@ fn generate_trait_methods( quote! { #stream_doc - type #stream: futures_core::Stream> + Send + 'static; + type #stream: futures_core::Stream> + Send + 'static; #method_doc async fn #name(&self, request: tonic::Request<#req_message>) - -> Result, tonic::Status>; + -> std::result::Result, tonic::Status>; } } (true, true) => { @@ -286,11 +286,11 @@ fn generate_trait_methods( quote! { #stream_doc - type #stream: futures_core::Stream> + Send + 'static; + type #stream: futures_core::Stream> + Send + 'static; #method_doc async fn #name(&self, request: tonic::Request>) - -> Result, tonic::Status>; + -> std::result::Result, tonic::Status>; } } }; diff --git a/tonic-health/src/generated/grpc.health.v1.rs b/tonic-health/src/generated/grpc.health.v1.rs index db0f1cbb8..835376aa2 100644 --- a/tonic-health/src/generated/grpc.health.v1.rs +++ b/tonic-health/src/generated/grpc.health.v1.rs @@ -119,7 +119,10 @@ pub mod health_client { pub async fn check( &mut self, request: impl tonic::IntoRequest, - ) -> Result, tonic::Status> { + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { self.inner .ready() .await @@ -153,7 +156,7 @@ pub mod health_client { pub async fn watch( &mut self, request: impl tonic::IntoRequest, - ) -> Result< + ) -> std::result::Result< tonic::Response>, tonic::Status, > { @@ -186,10 +189,13 @@ pub mod health_server { async fn check( &self, request: tonic::Request, - ) -> Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; /// Server streaming response type for the Watch method. type WatchStream: futures_core::Stream< - Item = Result, + Item = std::result::Result, > + Send + 'static; @@ -211,7 +217,7 @@ pub mod health_server { async fn watch( &self, request: tonic::Request, - ) -> Result, tonic::Status>; + ) -> std::result::Result, tonic::Status>; } #[derive(Debug)] pub struct HealthServer { @@ -266,7 +272,7 @@ pub mod health_server { fn poll_ready( &mut self, _cx: &mut Context<'_>, - ) -> Poll> { + ) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { diff --git a/tonic-reflection/src/generated/grpc.reflection.v1alpha.rs b/tonic-reflection/src/generated/grpc.reflection.v1alpha.rs index 1a97de9e3..450a2b1ff 100644 --- a/tonic-reflection/src/generated/grpc.reflection.v1alpha.rs +++ b/tonic-reflection/src/generated/grpc.reflection.v1alpha.rs @@ -218,7 +218,7 @@ pub mod server_reflection_client { request: impl tonic::IntoStreamingRequest< Message = super::ServerReflectionRequest, >, - ) -> Result< + ) -> std::result::Result< tonic::Response>, tonic::Status, > { @@ -248,7 +248,10 @@ pub mod server_reflection_server { pub trait ServerReflection: Send + Sync + 'static { /// Server streaming response type for the ServerReflectionInfo method. type ServerReflectionInfoStream: futures_core::Stream< - Item = Result, + Item = std::result::Result< + super::ServerReflectionResponse, + tonic::Status, + >, > + Send + 'static; @@ -257,7 +260,10 @@ pub mod server_reflection_server { async fn server_reflection_info( &self, request: tonic::Request>, - ) -> Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; } #[derive(Debug)] pub struct ServerReflectionServer { @@ -312,7 +318,7 @@ pub mod server_reflection_server { fn poll_ready( &mut self, _cx: &mut Context<'_>, - ) -> Poll> { + ) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future {