Last active
September 4, 2018 05:24
-
-
Save durka/ea4827c86fce413fff887a9d70859074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() -> ! { | |
let (mut delay, mut leds): (Delay, Leds) = aux5::init(); | |
loop { | |
foreach!($ | |
state => [on off] | |
period => [500 100] | |
{ | |
for led in 0..8 { | |
leds[led].$state(); | |
} | |
delay.delay_ms($period as u16); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! foreach { | |
(@go | |
() -> | |
([$($name:ident)*] [$([$($variant:tt)*])*]) | |
[$d:tt { $($body:tt)* }] | |
) => {{ | |
macro_rules! __foreach_substitute { | |
($($d$name:tt)*) => { | |
$($body)* | |
} | |
} | |
$(__foreach_substitute!($($variant)*);)* | |
}}; | |
(@go | |
($name:ident => [$($variant:tt)*] $($rest:tt)*) -> | |
([$($names:tt)*] [$([$($variants:tt)*])*]) | |
$thru:tt | |
) => { | |
foreach!(@go | |
($($rest)*) -> | |
([$($names)* $name] [$([$($variants)* $variant])*]) | |
$thru); | |
}; | |
( | |
$d:tt | |
$name:ident => [$($variant:tt)*] | |
$($names:ident => [$($variants:tt)*])* | |
{ $($body:tt)* } | |
) => { | |
foreach!(@go | |
($($names => [$($variants)*])*) -> | |
([$name] [$([$variant])*]) | |
[$d { $($body)* }]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment