Skip to content

Instantly share code, notes, and snippets.

@durka
Last active Sep 4, 2018
Embed
What would you like to do?
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);
});
}
}
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