I was contributing on pallet-assets and I found it hard to understand this syntax:
pub trait Config<I: 'static = ()>: frame_system::Config
Care to explain in details and examples?
Let's break it down:
pub trait Config<I: 'static = ()>: frame_system::Config
---------------- +++++++++++++++ xxxxxxxxxxxxxxxxxxxx
Every pallet has a trait Config
which allows you to configure the requirements of that pallet. This should not be new to you, as every pallet has this.
Some pallets are configured to be Instantiable. This allows the same Pallet to be used multiple times in the same runtime. The extra I
trait allows the user to do this, and by default, if the user does not implement I
, it will automatically be implemented to ()
which is default.
All pallets also require that they inherit the frame_system::Config
trait. This is also not new and something you will see in every pallet.
You can see usage of instances in Polkadot, where the Collective Pallet is used twice for two different collectives:
pub type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Config<CouncilCollective> for Runtime { ... }
pub type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Config<TechnicalCollective> for Runtime { ... }
In the case of default these two forms of syntax are the same:
// these two lines are the same, and having both in
// your code would trigger an duplication error.
impl pallet_collective::Config for Runtime { ... }
impl pallet_collective::Config<()> for Runtime { ... }
See also: Why is there a "lifetime" generic parameter in pallet_treasury?
[substrate-node]
tag on this question is not helpful or appropriate.