diff --git a/codegen/src/types/tests.rs b/codegen/src/types/tests.rs index c46403e6fa..94acde4684 100644 --- a/codegen/src/types/tests.rs +++ b/codegen/src/types/tests.rs @@ -312,8 +312,11 @@ fn generate_enum() { use super::root; #[derive(::subxt::codec::Encode, ::subxt::codec::Decode)] pub enum E { + # [codec (index = 0)] A, + # [codec (index = 1)] B (::core::primitive::bool,), + # [codec (index = 2)] C { a: ::core::primitive::u32, }, } } @@ -467,7 +470,9 @@ fn box_fields_enum() { use super::root; #[derive(::subxt::codec::Encode, ::subxt::codec::Decode)] pub enum E { + # [codec (index = 0)] A(::std::boxed::Box<::core::primitive::bool>,), + # [codec (index = 1)] B { a: ::std::boxed::Box<::core::primitive::u32>, }, } } diff --git a/codegen/src/types/type_def.rs b/codegen/src/types/type_def.rs index 12071296f0..2c432b88fe 100644 --- a/codegen/src/types/type_def.rs +++ b/codegen/src/types/type_def.rs @@ -139,7 +139,11 @@ impl<'a> quote::ToTokens for TypeDefGen<'a> { } else { self.composite_fields(v.fields(), &type_params, false) }; - variants.push(quote! { #variant_name #fields }); + let index = proc_macro2::Literal::u8_unsuffixed(v.index()); + variants.push(quote! { + #[codec(index = #index)] + #variant_name #fields + }); let unused_params_set = unused_type_params.iter().cloned().collect(); let used_params = type_params_set.difference(&unused_params_set);