grpc-rust icon indicating copy to clipboard operation
grpc-rust copied to clipboard

Avoid collisions with protobuf fields that are rust keywords

Open DazWilkin opened this issue 5 years ago • 0 comments

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.

DazWilkin avatar Apr 13 '20 18:04 DazWilkin