sui_proc_macros

Derive Macro EnumVariantOrder

Source
#[derive(EnumVariantOrder)]
Expand description

This proc macro generates a function order_to_variant_map which returns a map of the position of each variant to the name of the variant. It is intended to catch changes in enum order when backward compat is required.

   /// Example for this enum
   #[derive(EnumVariantOrder)]
   pub enum MyEnum {
        A,
        B(u64),
        C{x: bool, y: i8},
    }
    let order_map = MyEnum::order_to_variant_map();
    assert!(order_map.get(0).unwrap() == "A");
    assert!(order_map.get(1).unwrap() == "B");
    assert!(order_map.get(2).unwrap() == "C");