Skip to content
Snippets Groups Projects
Commit 20e80966 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Introduce the `Get` trait and type_parameter. (#2565)

parent 21773b3a
No related merge requests found
......@@ -61,7 +61,7 @@ pub use self::storage::{StorageList, StorageValue, StorageMap, EnumerableStorage
pub use self::hashable::Hashable;
pub use self::dispatch::{Parameter, Dispatchable, Callable, IsSubType};
pub use self::double_map::StorageDoubleMapWithHasher;
pub use runtime_io::print;
pub use runtime_io::{print, storage_root};
#[doc(inline)]
pub use srml_support_procedural::decl_storage;
......@@ -96,9 +96,9 @@ macro_rules! ensure {
#[cfg(feature = "std")]
macro_rules! assert_noop {
( $x:expr , $y:expr ) => {
let h = runtime_io::storage_root();
let h = $crate::storage_root();
$crate::assert_err!($x, $y);
assert_eq!(h, runtime_io::storage_root());
assert_eq!(h, $crate::storage_root());
}
}
......
......@@ -22,6 +22,45 @@ use crate::runtime_primitives::traits::{
MaybeSerializeDebug, SimpleArithmetic
};
/// New trait for querying a single fixed value from a type.
pub trait Get<T> {
/// Return a constant value.
fn get() -> T;
}
/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to
/// how you would declare a `const`:
///
/// ```no_compile
/// parameter_types! {
/// pub const Argument: u64 = 42;
/// }
/// trait Config {
/// type Parameter: Get<u64>;
/// }
/// struct Runtime;
/// impl Config for Runtime {
/// type Parameter = Argument;
/// }
/// ```
#[macro_export]
macro_rules! parameter_types {
(pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
pub struct $name;
parameter_types!{IMPL $name , $type , $value}
parameter_types!{ $( $rest )* }
);
(const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
struct $name;
parameter_types!{IMPL $name , $type , $value}
parameter_types!{ $( $rest )* }
);
() => ();
(IMPL $name:ident , $type:ty , $value:expr) => {
impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } }
}
}
/// The account with the given id was killed.
pub trait OnFreeBalanceZero<AccountId> {
/// The account was the given id was killed.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment