bincode-org / virtue

A sinless derive helper
MIT License
48 stars 10 forks source link

Enum variant fields are not allowed to be `pub`, so `EnumValue::add_pub_field` generates invalid Rust #86

Open NightEule5 opened 5 months ago

NightEule5 commented 5 months ago

When implementing generics, I found an oversight in enum generation:

generator
    .generate_enum("Foo")
    .add_value("Bar")
    .add_pub_field("bar", "u32");

// Generates:
enum Foo {
    Bar {
        pub bar: u32
    }
}

This does not compile, as the variant fields inherit the visibility of their parent enum:

error[E0449]: visibility qualifiers are not permitted here
 --> ...
  |
3 |         pub bar: u32
  |         ^^^
  |
  = note: enum variants and their fields always share the visibility of the enum they are in

This method appears to have been copied over from the struct generator code, as the documentation refers to structs. But it should be removed (or deprecated) from the enum variant code.