stepancheg / rust-protobuf

Rust implementation of Google protocol buffers
MIT License
2.81k stars 382 forks source link

Make all generated enums to have `#[repr(C)]` annotation #724

Closed Yury-Fridlyand closed 6 months ago

Yury-Fridlyand commented 6 months ago

In my project a enum generated by protobuf used in FFI. This requires enum to have #[repr(C)] annotation. Unfortunately, it is missing and we have to duplicate that enum manually and two-way conversion. That enum is rather big and we have to maintain 1k+ loc file on every update and deal with merge conflicts.

I think this annotation could be added to all enums by default, because it is never harmful. If it is not allowed, a configuration parameter is also ok.

Note: consider support multiple annotations. For example, we have #[repr(C)] and #[derive(Debug)].

ape-casear commented 6 months ago

the output of cmd protoc like this

// @@protoc_insertion_point(enum:ga.GRADE)
pub enum GRADE {
    // @@protoc_insertion_point(enum_value:ga.GRADE.CLASS_1)
    CLASS_1 = 1,
    // @@protoc_insertion_point(enum_value:ga.GRADE.CLASS_2)
    CLASS_2 = 2,
}

I remember that the official tells you could use sed or other tools to replace protoc_insertion_point with your annotations.

Yury-Fridlyand commented 6 months ago

Hi Thanks for sharing that! That actually a good idea, let me try.

Yury-Fridlyand commented 6 months ago

It works! Thanks!