macro_rules! define_versioned {
    (
        $(#[$attributes:meta])*
        $vis:vis enum $name:ident
        // Now match the optional type parameters
        // See https://stackoverflow.com/questions/41603424/rust-macro-accepting-type-with-generic-parameters
        $(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? $( = $deflt:tt)? ),+ >)?
        {
            $(
                previous_versions: [
                    $($version_num:expr => $version_type:ty: { updates_to: $update_to_version_num:expr }),*
                    $(,)? // Optional trailing comma
                ],
            )?
            latest_version: {
                $latest_version:expr => $latest_version_alias:ty = $latest_version_type:ty
                $(,)? // Optional trailing comma
            }
            $(,)? // Optional trailing comma
        }
    ) => { ... };
}
Expand description

This macro is intended for creating a data model which supports versioning. This is useful for creating an SBOR data model which can be updated in future. In future, enum variants can be added, and automatically mapped to.

NOTE: A circular version update chain will be an infinite loop at runtime. Be careful.

In the future, this may become a programmatic macro to support better error handling / edge case detection, and opting into more explicit SBOR handling.