Skip to content

Commit 184da12

Browse files
committed
Nifty macros for receiving from a protocol.
1 parent d594f37 commit 184da12

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

src/test/run-pass/pipe-bank-proto.rs

+14-42
Original file line numberDiff line numberDiff line change
@@ -45,65 +45,37 @@ fn move_it<T>(-x: T) -> T { x }
4545

4646
macro_rules! follow {
4747
{
48-
$($message:path($($x: ident),+) => $next:ident $e:expr)+
48+
$($message:path$(($($x: ident),+))||* -> $next:ident $e:expr)+
4949
} => (
50-
|m| match move_it(m) {
51-
$(some($message($($x,)* next)) {
50+
|m| match move m {
51+
$(some($message($($($x,)+)* next)) => {
5252
let $next = move_it!{next};
5353
$e })+
54-
_ { fail }
54+
_ => { fail }
5555
}
5656
);
57-
58-
{
59-
$($message:path => $next:ident $e:expr)+
60-
} => (
61-
|m| match move_it(m) {
62-
$(some($message(next)) {
63-
let $next = move_it!{next};
64-
$e })+
65-
_ { fail }
66-
}
67-
)
6857
}
6958

70-
/*
7159
fn client_follow(+bank: bank::client::login) {
7260
import bank::*;
7361

7462
let bank = client::login(bank, ~"theincredibleholk", ~"1234");
7563
let bank = switch(bank, follow! {
76-
ok => connected { connected }
77-
invalid => _next { fail ~"bank closed the connected" }
64+
ok -> connected { connected }
65+
invalid -> _next { fail ~"bank closed the connected" }
7866
});
7967
80-
/* // potential alternate syntax
81-
let bank = recv_alt! {
82-
bank => {
83-
| ok -> connected { connected }
84-
| invalid -> _next { fail }
85-
}
86-
bank2 => {
87-
| foo -> _n { fail }
88-
}
89-
}
90-
*/
91-
9268
let bank = client::deposit(bank, 100.00);
9369
let bank = client::withdrawal(bank, 50.00);
94-
match try_recv(bank) {
95-
some(money(m, _)) {
96-
io::println(~"Yay! I got money!");
97-
}
98-
some(insufficient_funds(_)) {
99-
fail ~"someone stole my money"
100-
}
101-
none {
102-
fail ~"bank closed the connection"
103-
}
104-
}
70+
switch(bank, follow! {
71+
money(m) -> _next {
72+
io::println(~"Yay! I got money!");
73+
}
74+
insufficient_funds -> _next {
75+
fail ~"someone stole my money"
76+
}
77+
});
10578
}
106-
*/
10779
10880
fn bank_client(+bank: bank::client::login) {
10981
import bank::*;

0 commit comments

Comments
 (0)