rust/src/test/run-pass/select-macro.rs

63 lines
1.5 KiB
Rust
Raw Normal View History

// xfail-test - this isn't really a test.
{
// select!
macro_rules! select_if (
{
$index:expr,
$count:expr
} => {
fail
};
{
$index:expr,
$count:expr,
$port:path => [
$(type_this $message:path$(($(x $x: ident),+))dont_type_this*
2012-09-19 00:45:24 -05:00
-> $next:ident => { move $e:expr }),+
]
$(, $ports:path => [
$(type_this $messages:path$(($(x $xs: ident),+))dont_type_this*
2012-09-19 00:45:24 -05:00
-> $nexts:ident => { move $es:expr }),+
] )*
} => {
if $index == $count {
match move pipes::try_recv($port) {
$(Some($message($($(move $x,)+)* move next)) => {
2012-09-19 00:45:24 -05:00
let $next = move next;
move $e
})+
_ => fail
}
} else {
2012-08-22 19:24:52 -05:00
select_if!(
$index,
$count + 1
$(, $ports => [
$(type_this $messages$(($(x $xs),+))dont_type_this*
2012-09-19 00:45:24 -05:00
-> $nexts => { move $es }),+
])*
2012-08-22 19:24:52 -05:00
)
}
};
)
macro_rules! select (
{
$( $port:path => {
$($message:path$(($($x: ident),+))dont_type_this*
-> $next:ident $e:expr),+
} )+
} => {
2012-10-09 23:28:04 -05:00
let index = pipes::selecti([$(($port).header()),+]);
2012-08-22 19:24:52 -05:00
select_if!(index, 0 $(, $port => [
2012-09-19 00:45:24 -05:00
$(type_this $message$(($(x $x),+))dont_type_this* -> $next => { move $e }),+
2012-08-22 19:24:52 -05:00
])+)
}
)
}