Skip to content
Snippets Groups Projects
Commit 2327b213 authored by Drew Stone's avatar Drew Stone Committed by Bastian Köcher
Browse files

Implement macro for session change trait over arbitrary tuples (limit 19) (#1177)

* Implement macro for session change trait

* Consolidate tuple macro into one
parent 1dc56b48
No related merge requests found
......@@ -51,19 +51,36 @@ pub trait OnSessionChange<T> {
fn on_session_change(time_elapsed: T, should_reward: bool);
}
impl<T> OnSessionChange<T> for () {
fn on_session_change(_: T, _: bool) {}
macro_rules! for_each_tuple {
($m:ident) => {
for_each_tuple! { @IMPL $m !! A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, }
};
(@IMPL $m:ident !!) => { $m! { } };
(@IMPL $m:ident !! $h:ident, $($t:ident,)*) => {
$m! { $h $($t)* }
for_each_tuple! { @IMPL $m !! $($t,)* }
}
}
impl<T, A, B> OnSessionChange<T> for (A, B)
where T: Clone, A: OnSessionChange<T>, B: OnSessionChange<T>
{
fn on_session_change(time_elapsed: T, should_reward: bool) {
A::on_session_change(time_elapsed.clone(), should_reward);
B::on_session_change(time_elapsed, should_reward);
macro_rules! impl_session_change {
() => (
impl<T> OnSessionChange<T> for () {
fn on_session_change(_: T, _: bool) {}
}
);
( $($t:ident)* ) => {
impl<T: Clone, $($t: OnSessionChange<T>),*> OnSessionChange<T> for ($($t,)*) {
fn on_session_change(time_elapsed: T, should_reward: bool) {
$($t::on_session_change(time_elapsed.clone(), should_reward);)*
}
}
}
}
for_each_tuple!(impl_session_change);
pub trait Trait: timestamp::Trait {
type ConvertAccountIdToSessionKey: Convert<Self::AccountId, Self::SessionKey>;
type OnSessionChange: OnSessionChange<Self::Moment>;
......
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