@@ -11,17 +11,17 @@ which both pattern-match on their input and both return early in one case,
11
11
doing nothing otherwise:
12
12
13
13
~~~~
14
- # enum t { special_a (uint), special_b (uint) };
14
+ # enum T { SpecialA (uint), SpecialB (uint) };
15
15
# fn f() -> uint {
16
- # let input_1 = special_a (0);
17
- # let input_2 = special_a (0);
16
+ # let input_1 = SpecialA (0);
17
+ # let input_2 = SpecialA (0);
18
18
match input_1 {
19
- special_a (x) => { return x; }
19
+ SpecialA (x) => { return x; }
20
20
_ => {}
21
21
}
22
22
// ...
23
23
match input_2 {
24
- special_b (x) => { return x; }
24
+ SpecialB (x) => { return x; }
25
25
_ => {}
26
26
}
27
27
# return 0u;
@@ -37,22 +37,22 @@ lightweight custom syntax extensions, themselves defined using the
37
37
the pattern in the above code:
38
38
39
39
~~~~
40
- # enum t { special_a (uint), special_b (uint) };
40
+ # enum T { SpecialA (uint), SpecialB (uint) };
41
41
# fn f() -> uint {
42
- # let input_1 = special_a (0);
43
- # let input_2 = special_a (0);
42
+ # let input_1 = SpecialA (0);
43
+ # let input_2 = SpecialA (0);
44
44
macro_rules! early_return(
45
- ($inp:expr $sp:ident) => ( // invoke it like `(input_5 special_e )`
45
+ ($inp:expr $sp:ident) => ( // invoke it like `(input_5 SpecialE )`
46
46
match $inp {
47
47
$sp(x) => { return x; }
48
48
_ => {}
49
49
}
50
50
);
51
51
)
52
52
// ...
53
- early_return!(input_1 special_a );
53
+ early_return!(input_1 SpecialA );
54
54
// ...
55
- early_return!(input_2 special_b );
55
+ early_return!(input_2 SpecialB );
56
56
# return 0;
57
57
# }
58
58
~~~~
@@ -155,10 +155,10 @@ separator token (a comma-separated list could be written `$(...),*`), and `+`
155
155
instead of ` * ` to mean "at least one".
156
156
157
157
~~~~
158
- # enum t { special_a (uint),special_b (uint),special_c (uint),special_d (uint)};
158
+ # enum T { SpecialA (uint),SpecialB (uint),SpecialC (uint),SpecialD (uint)};
159
159
# fn f() -> uint {
160
- # let input_1 = special_a (0);
161
- # let input_2 = special_a (0);
160
+ # let input_1 = SpecialA (0);
161
+ # let input_2 = SpecialA (0);
162
162
macro_rules! early_return(
163
163
($inp:expr, [ $($sp:ident)|+ ]) => (
164
164
match $inp {
@@ -170,9 +170,9 @@ macro_rules! early_return(
170
170
);
171
171
)
172
172
// ...
173
- early_return!(input_1, [special_a|special_c|special_d ]);
173
+ early_return!(input_1, [SpecialA|SpecialC|SpecialD ]);
174
174
// ...
175
- early_return!(input_2, [special_b ]);
175
+ early_return!(input_2, [SpecialB ]);
176
176
# return 0;
177
177
# }
178
178
~~~~
@@ -215,14 +215,14 @@ solves the problem.
215
215
Now consider code like the following:
216
216
217
217
~~~~
218
- # enum t1 { good_1(t2 , uint), bad_1 };
219
- # struct t2 { body: t3 }
220
- # enum t3 { good_2 (uint), bad_2 };
221
- # fn f(x: t1 ) -> uint {
218
+ # enum T1 { Good1(T2 , uint), Bad1 };
219
+ # struct T2 { body: T3 }
220
+ # enum T3 { Good2 (uint), Bad2 };
221
+ # fn f(x: T1 ) -> uint {
222
222
match x {
223
- good_1 (g1, val) => {
223
+ Good1 (g1, val) => {
224
224
match g1.body {
225
- good_2 (result) => {
225
+ Good2 (result) => {
226
226
// complicated stuff goes here
227
227
return result + val;
228
228
},
@@ -261,13 +261,13 @@ macro_rules! biased_match (
261
261
)
262
262
)
263
263
264
- # enum t1 { good_1(t2 , uint), bad_1 };
265
- # struct t2 { body: t3 }
266
- # enum t3 { good_2 (uint), bad_2 };
267
- # fn f(x: t1 ) -> uint {
268
- biased_match!((x) ~ (good_1 (g1, val)) else { return 0 };
264
+ # enum T1 { Good1(T2 , uint), Bad1 };
265
+ # struct T2 { body: T3 }
266
+ # enum T3 { Good2 (uint), Bad2 };
267
+ # fn f(x: T1 ) -> uint {
268
+ biased_match!((x) ~ (Good1 (g1, val)) else { return 0 };
269
269
binds g1, val )
270
- biased_match!((g1.body) ~ (good_2 (result) )
270
+ biased_match!((g1.body) ~ (Good2 (result) )
271
271
else { fail!("Didn't get good_2") };
272
272
binds result )
273
273
// complicated stuff goes here
@@ -365,13 +365,13 @@ macro_rules! biased_match (
365
365
)
366
366
367
367
368
- # enum t1 { good_1(t2 , uint), bad_1 };
369
- # struct t2 { body: t3 }
370
- # enum t3 { good_2 (uint), bad_2 };
371
- # fn f(x: t1 ) -> uint {
368
+ # enum T1 { Good1(T2 , uint), Bad1 };
369
+ # struct T2 { body: T3 }
370
+ # enum T3 { Good2 (uint), Bad2 };
371
+ # fn f(x: T1 ) -> uint {
372
372
biased_match!(
373
- (x) ~ (good_1 (g1, val)) else { return 0 };
374
- (g1.body) ~ (good_2 (result) ) else { fail!("Didn't get good_2 ") };
373
+ (x) ~ (Good1 (g1, val)) else { return 0 };
374
+ (g1.body) ~ (Good2 (result) ) else { fail!("Didn't get Good2 ") };
375
375
binds val, result )
376
376
// complicated stuff goes here
377
377
return result + val;
0 commit comments