Skip to content

Commit a562a3c

Browse files
authoredDec 21, 2022
fix(build): Allow Services to be named Result (#1203)
closes #1156
1 parent a72cf04 commit a562a3c

File tree

10 files changed

+86
-21
lines changed

10 files changed

+86
-21
lines changed
 

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ members = [
2222
"tests/root-crate-path",
2323
"tests/compression",
2424
"tonic-web/tests/integration",
25+
"tests/service_named_result",
2526
]

‎tests/service_named_result/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "service_named_result"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
prost = "0.11"
11+
tonic = {path = "../../tonic"}
12+
13+
[build-dependencies]
14+
tonic-build = {path = "../../tonic-build"}

‎tests/service_named_result/LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 Lucio Franco
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

‎tests/service_named_result/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
tonic_build::compile_protos("proto/result.proto").unwrap();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
syntax = "proto3";
2+
3+
import "google/protobuf/empty.proto";
4+
5+
package result;
6+
7+
service Result {
8+
rpc Listen(google.protobuf.Empty) returns (Reply) {}
9+
}
10+
11+
message Reply {
12+
int32 step = 1;
13+
}

‎tests/service_named_result/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod pb {
2+
tonic::include_proto!("result");
3+
}

‎tonic-build/src/client.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn generate_unary<T: Method>(
225225
pub async fn #ident(
226226
&mut self,
227227
request: impl tonic::IntoRequest<#request>,
228-
) -> Result<tonic::Response<#response>, tonic::Status> {
228+
) -> std::result::Result<tonic::Response<#response>, tonic::Status> {
229229
self.inner.ready().await.map_err(|e| {
230230
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
231231
})?;
@@ -251,7 +251,7 @@ fn generate_server_streaming<T: Method>(
251251
pub async fn #ident(
252252
&mut self,
253253
request: impl tonic::IntoRequest<#request>,
254-
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
254+
) -> std::result::Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
255255
self.inner.ready().await.map_err(|e| {
256256
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
257257
})?;
@@ -277,7 +277,7 @@ fn generate_client_streaming<T: Method>(
277277
pub async fn #ident(
278278
&mut self,
279279
request: impl tonic::IntoStreamingRequest<Message = #request>
280-
) -> Result<tonic::Response<#response>, tonic::Status> {
280+
) -> std::result::Result<tonic::Response<#response>, tonic::Status> {
281281
self.inner.ready().await.map_err(|e| {
282282
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
283283
})?;
@@ -303,7 +303,7 @@ fn generate_streaming<T: Method>(
303303
pub async fn #ident(
304304
&mut self,
305305
request: impl tonic::IntoStreamingRequest<Message = #request>
306-
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
306+
) -> std::result::Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
307307
self.inner.ready().await.map_err(|e| {
308308
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
309309
})?;

‎tonic-build/src/server.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(crate) fn generate_internal<T: Service>(
144144
type Error = std::convert::Infallible;
145145
type Future = BoxFuture<Self::Response, Self::Error>;
146146

147-
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
147+
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
148148
Poll::Ready(Ok(()))
149149
}
150150

@@ -251,14 +251,14 @@ fn generate_trait_methods<T: Service>(
251251
quote! {
252252
#method_doc
253253
async fn #name(&self, request: tonic::Request<#req_message>)
254-
-> Result<tonic::Response<#res_message>, tonic::Status>;
254+
-> std::result::Result<tonic::Response<#res_message>, tonic::Status>;
255255
}
256256
}
257257
(true, false) => {
258258
quote! {
259259
#method_doc
260260
async fn #name(&self, request: tonic::Request<tonic::Streaming<#req_message>>)
261-
-> Result<tonic::Response<#res_message>, tonic::Status>;
261+
-> std::result::Result<tonic::Response<#res_message>, tonic::Status>;
262262
}
263263
}
264264
(false, true) => {
@@ -270,11 +270,11 @@ fn generate_trait_methods<T: Service>(
270270

271271
quote! {
272272
#stream_doc
273-
type #stream: futures_core::Stream<Item = Result<#res_message, tonic::Status>> + Send + 'static;
273+
type #stream: futures_core::Stream<Item = std::result::Result<#res_message, tonic::Status>> + Send + 'static;
274274

275275
#method_doc
276276
async fn #name(&self, request: tonic::Request<#req_message>)
277-
-> Result<tonic::Response<Self::#stream>, tonic::Status>;
277+
-> std::result::Result<tonic::Response<Self::#stream>, tonic::Status>;
278278
}
279279
}
280280
(true, true) => {
@@ -286,11 +286,11 @@ fn generate_trait_methods<T: Service>(
286286

287287
quote! {
288288
#stream_doc
289-
type #stream: futures_core::Stream<Item = Result<#res_message, tonic::Status>> + Send + 'static;
289+
type #stream: futures_core::Stream<Item = std::result::Result<#res_message, tonic::Status>> + Send + 'static;
290290

291291
#method_doc
292292
async fn #name(&self, request: tonic::Request<tonic::Streaming<#req_message>>)
293-
-> Result<tonic::Response<Self::#stream>, tonic::Status>;
293+
-> std::result::Result<tonic::Response<Self::#stream>, tonic::Status>;
294294
}
295295
}
296296
};

‎tonic-health/src/generated/grpc.health.v1.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ pub mod health_client {
119119
pub async fn check(
120120
&mut self,
121121
request: impl tonic::IntoRequest<super::HealthCheckRequest>,
122-
) -> Result<tonic::Response<super::HealthCheckResponse>, tonic::Status> {
122+
) -> std::result::Result<
123+
tonic::Response<super::HealthCheckResponse>,
124+
tonic::Status,
125+
> {
123126
self.inner
124127
.ready()
125128
.await
@@ -153,7 +156,7 @@ pub mod health_client {
153156
pub async fn watch(
154157
&mut self,
155158
request: impl tonic::IntoRequest<super::HealthCheckRequest>,
156-
) -> Result<
159+
) -> std::result::Result<
157160
tonic::Response<tonic::codec::Streaming<super::HealthCheckResponse>>,
158161
tonic::Status,
159162
> {
@@ -186,10 +189,13 @@ pub mod health_server {
186189
async fn check(
187190
&self,
188191
request: tonic::Request<super::HealthCheckRequest>,
189-
) -> Result<tonic::Response<super::HealthCheckResponse>, tonic::Status>;
192+
) -> std::result::Result<
193+
tonic::Response<super::HealthCheckResponse>,
194+
tonic::Status,
195+
>;
190196
/// Server streaming response type for the Watch method.
191197
type WatchStream: futures_core::Stream<
192-
Item = Result<super::HealthCheckResponse, tonic::Status>,
198+
Item = std::result::Result<super::HealthCheckResponse, tonic::Status>,
193199
>
194200
+ Send
195201
+ 'static;
@@ -211,7 +217,7 @@ pub mod health_server {
211217
async fn watch(
212218
&self,
213219
request: tonic::Request<super::HealthCheckRequest>,
214-
) -> Result<tonic::Response<Self::WatchStream>, tonic::Status>;
220+
) -> std::result::Result<tonic::Response<Self::WatchStream>, tonic::Status>;
215221
}
216222
#[derive(Debug)]
217223
pub struct HealthServer<T: Health> {
@@ -266,7 +272,7 @@ pub mod health_server {
266272
fn poll_ready(
267273
&mut self,
268274
_cx: &mut Context<'_>,
269-
) -> Poll<Result<(), Self::Error>> {
275+
) -> Poll<std::result::Result<(), Self::Error>> {
270276
Poll::Ready(Ok(()))
271277
}
272278
fn call(&mut self, req: http::Request<B>) -> Self::Future {

‎tonic-reflection/src/generated/grpc.reflection.v1alpha.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub mod server_reflection_client {
218218
request: impl tonic::IntoStreamingRequest<
219219
Message = super::ServerReflectionRequest,
220220
>,
221-
) -> Result<
221+
) -> std::result::Result<
222222
tonic::Response<tonic::codec::Streaming<super::ServerReflectionResponse>>,
223223
tonic::Status,
224224
> {
@@ -248,7 +248,10 @@ pub mod server_reflection_server {
248248
pub trait ServerReflection: Send + Sync + 'static {
249249
/// Server streaming response type for the ServerReflectionInfo method.
250250
type ServerReflectionInfoStream: futures_core::Stream<
251-
Item = Result<super::ServerReflectionResponse, tonic::Status>,
251+
Item = std::result::Result<
252+
super::ServerReflectionResponse,
253+
tonic::Status,
254+
>,
252255
>
253256
+ Send
254257
+ 'static;
@@ -257,7 +260,10 @@ pub mod server_reflection_server {
257260
async fn server_reflection_info(
258261
&self,
259262
request: tonic::Request<tonic::Streaming<super::ServerReflectionRequest>>,
260-
) -> Result<tonic::Response<Self::ServerReflectionInfoStream>, tonic::Status>;
263+
) -> std::result::Result<
264+
tonic::Response<Self::ServerReflectionInfoStream>,
265+
tonic::Status,
266+
>;
261267
}
262268
#[derive(Debug)]
263269
pub struct ServerReflectionServer<T: ServerReflection> {
@@ -312,7 +318,7 @@ pub mod server_reflection_server {
312318
fn poll_ready(
313319
&mut self,
314320
_cx: &mut Context<'_>,
315-
) -> Poll<Result<(), Self::Error>> {
321+
) -> Poll<std::result::Result<(), Self::Error>> {
316322
Poll::Ready(Ok(()))
317323
}
318324
fn call(&mut self, req: http::Request<B>) -> Self::Future {

0 commit comments

Comments
 (0)
Please sign in to comment.