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

Manual index annotation for Encodable enums #5296

Closed
elsirion opened this issue May 15, 2024 · 0 comments · Fixed by #5304
Closed

Manual index annotation for Encodable enums #5296

elsirion opened this issue May 15, 2024 · 0 comments · Fixed by #5304

Comments

@elsirion
Copy link
Contributor

As we add and remove enum variants of non-consensus enums over time it will often be easier to accept "holes" in the numbering scheme than writing DB migrations that increment/decrement every variant index by one.

For example:

#[derive(Encodable)]
enum MyEnum {
    Foo, // idx=0
    Bar, // idx=1
    Baz, // idx=2
}

is changed to

#[derive(Encodable)]
enum MyEnum {
    Foo, // idx=0
    Baz, // idx=1
}

now we'd have to write a DB migration that decodes the old Baz values with variant index 2 and re-encodes them with index 1. Instead we could allow the following annotation:

#[derive(Encodable)]
enum MyEnum {
    #[encodable_index = 0]
    Foo, // idx=0
    // note how idx=1 is missing
    #[encodable_index = 2]
    Baz, // idx=2
}
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.

1 participant