@@ -2186,7 +2186,7 @@ match_pat : pat [ ".." pat ] ? [ "if" expr ] ;
2186
2186
2187
2187
A ` match ` expression branches on a * pattern* . The exact form of matching that
2188
2188
occurs depends on the pattern. Patterns consist of some combination of
2189
- literals, destructured enum constructors, records and tuples, variable binding
2189
+ literals, destructured enum constructors, structures, records and tuples, variable binding
2190
2190
specifications, wildcards (` * ` ), and placeholders (` _ ` ). A ` match ` expression has a * head
2191
2191
expression* , which is the value to compare to the patterns. The type of the
2192
2192
patterns must equal the type of the head expression.
@@ -2196,19 +2196,19 @@ In a pattern whose head expression has an `enum` type, a placeholder (`_`) stand
2196
2196
variant. For example:
2197
2197
2198
2198
~~~~
2199
- enum list <X> { nil, cons (X, @list <X>) }
2199
+ enum List <X> { Nil, Cons (X, @List <X>) }
2200
2200
2201
- let x: list <int> = cons (10, @cons (11, @nil ));
2201
+ let x: List <int> = Cons (10, @Cons (11, @Nil ));
2202
2202
2203
2203
match x {
2204
- cons (_, @nil ) => fail ~"singleton list",
2205
- cons (*) => return,
2206
- nil => fail ~"empty list"
2204
+ Cons (_, @Nil ) => fail ~"singleton list",
2205
+ Cons (*) => return,
2206
+ Nil => fail ~"empty list"
2207
2207
}
2208
2208
~~~~
2209
2209
2210
- The first pattern matches lists constructed by applying ` cons ` to any head value, and a
2211
- tail value of ` @nil ` . The second pattern matches ` any ` list constructed with ` cons ` ,
2210
+ The first pattern matches lists constructed by applying ` Cons ` to any head value, and a
2211
+ tail value of ` @Nil ` . The second pattern matches _ any _ list constructed with ` Cons ` ,
2212
2212
ignoring the values of its arguments. The difference between ` _ ` and ` * ` is that the pattern ` C(_) ` is only type-correct if
2213
2213
` C ` has exactly one argument, while the pattern ` C(*) ` is type-correct for any enum variant ` C ` , regardless of how many arguments ` C ` has.
2214
2214
@@ -2225,18 +2225,18 @@ An example of an `match` expression:
2225
2225
# fn process_pair(a: int, b: int) { }
2226
2226
# fn process_ten() { }
2227
2227
2228
- enum list <X> { nil, cons (X, @list <X>) }
2228
+ enum List <X> { Nil, Cons (X, @List <X>) }
2229
2229
2230
- let x: list <int> = cons (10, @cons (11, @nil ));
2230
+ let x: List <int> = Cons (10, @Cons (11, @Nil ));
2231
2231
2232
2232
match x {
2233
- cons (a, @cons (b, _)) => {
2233
+ Cons (a, @Cons (b, _)) => {
2234
2234
process_pair(a,b);
2235
2235
}
2236
- cons (10, _) => {
2236
+ Cons (10, _) => {
2237
2237
process_ten();
2238
2238
}
2239
- nil => {
2239
+ Nil => {
2240
2240
return;
2241
2241
}
2242
2242
_ => {
@@ -2245,7 +2245,7 @@ match x {
2245
2245
}
2246
2246
~~~~
2247
2247
2248
- Records can also be pattern-matched and their fields bound to variables.
2248
+ Records and structures can also be pattern-matched and their fields bound to variables.
2249
2249
When matching fields of a record, the fields being matched are specified
2250
2250
first, then a placeholder (` _ ` ) represents the remaining fields.
2251
2251
0 commit comments