near / borsh

Binary Object Representation Serializer for Hashing

Home Page:https://borsh.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow skipping enum variant numbers

mina86 opened this issue · comments

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());