Make parameter types implementation more flexible (#3112)

* Make parameter types implementation more flexible

* Bump `impl_version`
This commit is contained in:
Bastian Köcher
2019-07-13 10:54:41 +02:00
committed by Gavin Wood
parent 9ee79d5c5e
commit c42d73d302
5 changed files with 68 additions and 64 deletions
+17 -8
View File
@@ -85,19 +85,28 @@ pub use runtime_primitives::ConsensusEngineId;
/// ```
#[macro_export]
macro_rules! parameter_types {
(pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
pub struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::parameter_types!{ $( $rest )* }
);
(const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
struct $name;
(
$( #[ $attr:meta ] )*
$vis:vis const $name:ident: $type:ty = $value:expr;
$( $rest:tt )*
) => (
$( #[ $attr ] )*
$vis struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::parameter_types!{ $( $rest )* }
);
() => ();
(IMPL $name:ident , $type:ty , $value:expr) => {
impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } }
impl $name {
fn get() -> $type {
$value
}
}
impl<I: From<$type>> $crate::traits::Get<I> for $name {
fn get() -> I {
I::from($value)
}
}
}
}