stepancheg / grpc-rust

Rust implementation of gRPC
MIT License
1.38k stars 125 forks source link

protoc-rust-grpc doesn't take care of keywords such as async #167

Open jschwinger233 opened 4 years ago

jschwinger233 commented 4 years ago

considering the protobuf message possesses a field async, the generated grpc rust code will irritate compiler under 2018 edition.

here's a simple demonstration, add two lines in greeting example repo:

greeter $ git diff
diff --git a/grpc-examples/greeter/Cargo.toml b/grpc-examples/greeter/Cargo.toml
index 4477fde..4a5bc33 100644
--- a/grpc-examples/greeter/Cargo.toml
+++ b/grpc-examples/greeter/Cargo.toml
@@ -3,6 +3,7 @@ name = "grpc_examples_greeter"
 version = "0.0.0"
 authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"]
 publish = false
+edition = "2018"

 [lib]
 doctest = false
diff --git a/grpc-examples/greeter/helloworld.proto b/grpc-examples/greeter/helloworld.proto
index 0bee1fc..dc3f75d 100644
--- a/grpc-examples/greeter/helloworld.proto
+++ b/grpc-examples/greeter/helloworld.proto
@@ -45,6 +45,7 @@ service Greeter {
 // The request message containing the user's name.
 message HelloRequest {
   string name = 1;
+  bool async = 2;
 }

 // The response message containing the greetings

and rustc would complain

error: expected identifier, found reserved keyword `async`
   --> grpc-examples/greeter/src/helloworld.rs:216:14
    |
216 |         self.async = false;
    |              ^^^^^ expected identifier, found reserved keyword
help: you can escape reserved keywords to use them as identifiers
    |
216 |         self.r#async = false;
    |              ^^^^^^^

error: aborting due to 11 previous errors

error: Could not compile `grpc_examples_greeter`.