Macro subsocial_runtime::parameter_types [−][src]
Create new implementations of the Get trait.
The so-called parameter type can be created in three different ways:
-
Using
constto create a parameter type that provides aconstgetter. It is required that thevalueis const. -
Declare the parameter type without
constto have more freedom when creating the value. -
Using
storageto create a storage parameter type. This type is special as it tries to load the value from the storage under a fixed key. If the value could not be found in the storage, the given default value will be returned. It is required that the value implementsEncodeandDecode. The key for looking up the value in the storage is built using the following formular:twox_128(":" ++ NAME ++ ":")whereNAMEis the name that is passed as type name.
Examples
// This function cannot be used in a const context. fn non_const_expression() -> u64 { 99 } const FIXED_VALUE: u64 = 10; parameter_types! { pub const Argument: u64 = 42 + FIXED_VALUE; /// Visibility of the type is optional OtherArgument: u64 = non_const_expression(); pub storage StorageArgument: u64 = 5; } trait Config { type Parameter: Get<u64>; type OtherParameter: Get<u64>; type StorageParameter: Get<u64>; } struct Runtime; impl Config for Runtime { type Parameter = Argument; type OtherParameter = OtherArgument; type StorageParameter = StorageArgument; }
Invalid example:
// This function cannot be used in a const context. fn non_const_expression() -> u64 { 99 } parameter_types! { pub const Argument: u64 = non_const_expression(); }