From 80c685cbc692008fa70ddeeb0da25a46e2059f2f Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Jan 2024 14:36:15 +0100 Subject: [PATCH] impl `Get` for RuntimeFreezeReason/RuntimeHoldReason --- .../src/construct_runtime/expand/freeze_reason.rs | 7 +++++++ .../procedural/src/construct_runtime/expand/hold_reason.rs | 7 +++++++ substrate/frame/support/src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs index e612cd6209e2..84aedee0c792 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs @@ -76,6 +76,13 @@ pub fn expand_outer_freeze_reason(pallet_decls: &[Pallet], scrate: &TokenStream) const VARIANT_COUNT: u32 = #( #freeze_reason_variants_count )+*; } + /// Implementation of `Get` which returns `RuntimeFreezeReason::VARIANT_COUNT`. + impl #scrate::traits::Get for RuntimeFreezeReason { + fn get() -> u32 { + ::VARIANT_COUNT + } + } + #( #conversion_fns )* } } diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs index b0ad8397f37d..7391bc80dee4 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs @@ -76,6 +76,13 @@ pub fn expand_outer_hold_reason(pallet_decls: &[Pallet], scrate: &TokenStream) - const VARIANT_COUNT: u32 = #( #hold_reason_variants_count )+*; } + /// Implementation of `Get` which returns `RuntimeHoldReason::VARIANT_COUNT`. + impl #scrate::traits::Get for RuntimeHoldReason { + fn get() -> u32 { + ::VARIANT_COUNT + } + } + #( #conversion_fns )* } } diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index b986610e5bd4..9666fff1dddd 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -1675,7 +1675,7 @@ pub mod pallet_prelude { /// the enum: /// /// ```ignore -/// Copy, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug +/// Copy, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug, CompositeEnumVariantCount /// ``` /// /// The inverse is also true: if there are any #[derive] attributes present for the enum, then