Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Customize::oneofs_non_exhaustive to false doesn't work #747

Open
5tan opened this issue Nov 7, 2024 · 1 comment · May be fixed by #748
Open

Setting Customize::oneofs_non_exhaustive to false doesn't work #747

5tan opened this issue Nov 7, 2024 · 1 comment · May be fixed by #748

Comments

@5tan
Copy link

5tan commented Nov 7, 2024

I have tried:

fn main() {
    let customize = protobuf_codegen::Customize::default()
        .generate_accessors(true)
        .generate_getter(true)
        .oneofs_non_exhaustive(false); // <--- !!!

    protobuf_codegen::Codegen::new()
        .inputs(&vec!["my_message.proto"])
        .out_dir(".")
        .include(".")
        .customize(customize)
        .run()
        .expect("Running protoc failed.");
}

Example proto:

syntax = "proto3";

message MyMessage {
    string one = 1;
    oneof MyEnum {
        string two = 2;
        string three = 3;
    }
}

Result:

// (...)
/// Nested message and enums of message `MyMessage`
pub mod my_message {

    #[derive(Clone,PartialEq,Debug)]
    #[non_exhaustive]
    // @@protoc_insertion_point(oneof:MyMessage.MyEnum)
    pub enum MyEnum {
        // @@protoc_insertion_point(oneof_field:MyMessage.two)
        Two(::std::string::String),
        // @@protoc_insertion_point(oneof_field:MyMessage.three)
        Three(::std::string::String),
    }
// (...)

versions:

protobuf = "3.7.1"
protobuf-codegen = "3.7.1"
@akonradi-signal
Copy link
Contributor

Sorry about that! I wrote the feature and then didn't end up using it and so didn't notice the bug. #748 has the fix, and hopefully will make it harder to make the same mistake I did (handling a field in one place but not another).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants