[][src]Macro frame_support::parameter_types

macro_rules! parameter_types {
    (
		$( #[ $attr:meta ] )*
		$vis:vis const $name:ident: $type:ty = $value:expr;
		$( $rest:tt )*
	) => { ... };
    (
		$( #[ $attr:meta ] )*
		$vis:vis $name:ident: $type:ty = $value:expr;
		$( $rest:tt )*
	) => { ... };
    (
		$( #[ $attr:meta ] )*
		$vis:vis storage $name:ident: $type:ty = $value:expr;
		$( $rest:tt )*
	) => { ... };
    () => { ... };
    (IMPL_CONST $name:ident, $type:ty, $value:expr) => { ... };
    (IMPL $name:ident, $type:ty, $value:expr) => { ... };
    (IMPL_STORAGE $name:ident, $type:ty, $value:expr) => { ... };
}

Create new implementations of the Get trait.

The so-called parameter type can be created in three different ways:

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 example deliberately fails to compile
// This function cannot be used in a const context.
fn non_const_expression() -> u64 { 99 }

parameter_types! {
   pub const Argument: u64 = non_const_expression();
}