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

Allow skipping enum variant numbers #129

Open
mina86 opened this issue Aug 15, 2022 · 0 comments
Open

Allow skipping enum variant numbers #129

mina86 opened this issue Aug 15, 2022 · 0 comments

Comments

@mina86
Copy link

mina86 commented Aug 15, 2022

Currently it’s not possible to remove a variant from an enum because that affects numeration of variants that follow and that in turn affects backward compatibility. We need a way to signal in type definition that a variant number is no longer valid. Perhaps something like

#[derive(PartialEq, borsh::BorshSerialize, borsh::BorshDeserialize)]
enum Ordinal {
    One,
    Two,
    Many
}

becoming

#[derive(PartialEq, borsh::BorshSerialize, borsh::BorshDeserialize)]
enum Ordinal {
    One,
    #[borsh_unused(Two)],
    Many
}

with the expectation that:

assert!(Ordinal::try_from_slice(&[1]).is_err());
assert_eq!(Ordinal::Many, Ordinal::try_from_slice(&[2]).unwrap());
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

No branches or pull requests

1 participant