stepancheg / grpc-rust

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

Avoid collisions with protobuf fields that are rust keywords #179

Open DazWilkin opened 4 years ago

DazWilkin commented 4 years ago

E.g. googleapis/google/api/auth.proto#JwtLocation:

// Specifies a location to extract JWT from an API request.
message JwtLocation {
  oneof in {
    // Specifies HTTP header name to extract JWT token.
    string header = 1;

    // Specifies URL query parameter name to extract JWT token.
    string query = 2;
  }

protoc_rust_grpc generates:

auth.rs:

#[derive(PartialEq,Clone,Default)]
pub struct JwtLocation {
    // message fields
    pub value_prefix: ::std::string::String,
    // message oneof groups
    pub in: ::std::option::Option<JwtLocation_oneof_in>,
    // special fields
    pub unknown_fields: ::protobuf::UnknownFields,
    pub cached_size: ::protobuf::CachedSize,
}

Results in:

expected identifier, found keyword `in`

expected identifier, found keyword

help: you can escape reserved keywords to use them as identifiers: `r#in`

It's unclear to me whether prefixing all|keyword fields with raw string literals would address this issue comprehensively.