Attribute Macro frame_support::pallet_macros::composite_enum

source ·
#[composite_enum]
Expand description

Allows defining an enum that gets composed as an aggregate enum by construct_runtime.

The #[pallet::composite_enum] attribute allows you to define an enum that gets composed as an aggregate enum by construct_runtime. This is similar in principle with frame_support_procedural::event and frame_support_procedural::error.

The attribute currently only supports enum definitions, and identifiers that are named FreezeReason, HoldReason, LockId or SlashReason. Arbitrary identifiers for the enum are not supported. The aggregate enum generated by frame_support::construct_runtime will have the name of RuntimeFreezeReason, RuntimeHoldReason, RuntimeLockId and RuntimeSlashReason respectively.

NOTE: The aggregate enum generated by construct_runtime generates a conversion function from the pallet enum to the aggregate enum, and automatically derives the following traits:

Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, TypeInfo,
RuntimeDebug

For ease of usage, when no #[derive] attributes are found for the enum under #[pallet::composite_enum], the aforementioned traits are automatically derived for it. The inverse is also true: if there are any #[derive] attributes found for the enum, then no traits will automatically be derived for it.

e.g, defining HoldReason in a pallet

#[frame_support::pallet]
mod pallet {
	#[pallet::pallet]
	pub struct Pallet<T>(_);

	#[pallet::composite_enum]
	pub enum HoldReason {
		/// The NIS Pallet has reserved it for a non-fungible receipt.
		#[codec(index = 0)]
		SomeHoldReason,
		#[codec(index = 1)]
		SomeOtherHoldReason,
	}
}

---

Documentation for this macro can be found at `frame_support::pallet_macros::composite_enum`.