There seems to be different approaches to declaring constants for a pallet's runtime implementation.
- A common approach for example is:
// In pallet/example/src/lib.rs
#[pallet::config]
pub trait Config: frame_system::Config {
// --snip --
const SOME_CONSTANT: u32;
}
// In runtime/src/lib.rs
impl pallet_example::Config for Runtime {
const SOME_CONSTANT: u32 = 42;
}
- Another way is to use
ConstU32
. For example:
// In pallet/example/src/lib.rs
#[pallet::config]
pub trait Config: frame_system::Config {
// --snip --
#[pallet::constant]
type SomeConstant: Get<u32>;
}
// In runtime/src/lib.rs
impl pallet_example::Config for Runtime {
type SomeConstant = ConstU32<42>;
}
- A third approach would be to use the
parameter_types
types macro, which is most commonly used to declare constants of custom types, but can also be used for any other type.
How do I know which approach to use? Why would I choose one over the other?