File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ // xfail-pretty
2
+
3
+ // An example of the bank protocol from eholk's blog post.
4
+ //
5
+ // http://theincredibleholk.wordpress.com/2012/07/06/rusty-pipes/
6
+
7
+ import pipes:: recv;
8
+
9
+ type username = str ;
10
+ type password = str ;
11
+ type money = float ;
12
+ type amount = float ;
13
+
14
+ proto ! bank {
15
+ login: send {
16
+ login( username, password) -> login_response
17
+ }
18
+
19
+ login_response: recv {
20
+ ok -> connected,
21
+ invalid -> login
22
+ }
23
+
24
+ connected: send {
25
+ deposit( money) -> connected,
26
+ withdrawal( amount) -> withdrawal_response
27
+ }
28
+
29
+ withdrawal_response: recv {
30
+ money( money) -> connected,
31
+ insufficient_funds -> connected
32
+ }
33
+ }
34
+
35
+ fn macros ( ) {
36
+ #macro[
37
+ [ #move[ x] ,
38
+ unsafe { let y <- * ptr:: addr_of ( x ) ; y } ]
39
+ ] ;
40
+ }
41
+
42
+ fn bank_client ( +bank : bank:: client:: login ) {
43
+ import bank:: * ;
44
+
45
+ let bank = client:: login ( bank, "theincredibleholk" , "1234" ) ;
46
+ let bank = alt recv ( bank) {
47
+ some ( ok ( connected) ) {
48
+ #move( connected)
49
+ }
50
+ some ( invalid ( _) ) { fail "login unsuccessful" }
51
+ none { fail "bank closed the connection" }
52
+ } ;
53
+
54
+ let bank = client:: deposit ( bank, 100.00 ) ;
55
+ let bank = client:: withdrawal ( bank, 50.00 ) ;
56
+ alt recv( bank) {
57
+ some ( money ( m, _) ) {
58
+ io:: println ( "Yay! I got money!" ) ;
59
+ }
60
+ some ( insufficient_funds ( _) ) {
61
+ fail "someone stole my money"
62
+ }
63
+ none {
64
+ fail "bank closed the connection"
65
+ }
66
+ }
67
+ }
68
+
69
+ fn main ( ) {
70
+ }
You can’t perform that action at this time.
0 commit comments