Skip to content

Error Compiling Default String Field With Bytes  #395

@dharesign

Description

@dharesign

I'm using protobuf-codegen-pure = "2.3", and running into the following issue.

Given foo.proto:

message Foo {
    optional string bar = 1 [default = "test"];
}

The generated foo.rs:

impl Foo {
    pub fn mut_bar(&mut self) -> &mut ::protobuf::Chars {
        if self.bar.is_none() {
            self.bar = ::std::option::Option::Some("test");
        }
        self.bar.as_mut().unwrap()
    }
}

Fails to compile:

error[E0308]: mismatched types
  --> src/foo.rs:57:52
   |
57 |             self.bar = ::std::option::Option::Some("test");
   |                                                    ^^^^^^ expected struct `protobuf::chars::Chars`, found reference
   |
   = note: expected type `protobuf::chars::Chars`
              found type `&'static str`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions