twilight icon indicating copy to clipboard operation
twilight copied to clipboard

Transform enum struct variants into separate structs for backwards compatibility

Open 7596ff opened this issue 5 years ago • 1 comments

pub enum Foo {
    Bar {
        a: String,
        b: i32,
    }
}

becomes

#[non_exhaustive]
pub enum Foo {
    Bar(Bar),
}

#[non_exhaustive]
pub struct Bar {
    pub a: String,
    pub b: i32,
}

7596ff avatar Feb 18 '21 21:02 7596ff

I'd just like to note that this too is valid rust:

#[non_exhaustive]
pub enum Foo {
    #[non_exhaustive]
    Bar { a: String, b: i32 },
}

There's no need to split them into separate types just for the #[non_exhaustive] attribute, see https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute

vilgotf avatar Feb 15 '23 08:02 vilgotf