You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A [_vector_](#vector-types)_expression_ is written by enclosing zero or
@@ -1584,7 +1558,6 @@ When no mutability is specified, the vector is immutable.
1584
1558
~~~~
1585
1559
[1, 2, 3, 4];
1586
1560
["a", "b", "c", "d"];
1587
-
[0, ..128]; // vector with 128 zeros
1588
1561
[mut 0u8, 0u8, 0u8, 0u8];
1589
1562
~~~~
1590
1563
@@ -1916,7 +1889,7 @@ let x: int = add(1, 2);
1916
1889
1917
1890
~~~~~~~~{.abnf .gram}
1918
1891
ident_list : [ ident [ ',' ident ]* ] ? ;
1919
-
lambda_expr : '|' ident_list '|' expr ;
1892
+
lambda_expr : '|' ident_list '| expr ;
1920
1893
~~~~~~~~
1921
1894
1922
1895
A _lambda expression_ (a.k.a. "anonymous function expression") defines a function and denotes it as a value,
@@ -2197,6 +2170,17 @@ When matching fields of a record,
2197
2170
the fields being matched are specified first,
2198
2171
then a placeholder (`_`) represents the remaining fields.
2199
2172
2173
+
A pattern that's just a variable binding,
2174
+
like `Nil` in the previous answer,
2175
+
could either refer to an enum variant that's in scope,
2176
+
or bind a new variable.
2177
+
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2178
+
For example, wherever ```List``` is in scope,
2179
+
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2180
+
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2181
+
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2182
+
and local variables with lower-case letters.
2183
+
2200
2184
~~~~
2201
2185
# type options = {choose: bool, size: ~str};
2202
2186
# type player = {player: ~str, stats: (), options: options};
@@ -2228,22 +2212,6 @@ fn main() {
2228
2212
}
2229
2213
~~~~
2230
2214
2231
-
Patterns that bind variables default to binding to a copy of the matched value. This can be made
2232
-
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
2233
-
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
2234
-
the new binding using ```move```.
2235
-
2236
-
A pattern that's just an identifier,
2237
-
like `Nil` in the previous answer,
2238
-
could either refer to an enum variant that's in scope,
2239
-
or bind a new variable.
2240
-
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2241
-
For example, wherever ```List``` is in scope,
2242
-
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2243
-
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2244
-
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2245
-
and local variables with lower-case letters.
2246
-
2247
2215
Multiple match patterns may be joined with the `|` operator. A
2248
2216
range of values may be specified with `..`. For example:
2249
2217
@@ -2726,12 +2694,11 @@ The kinds are:
2726
2694
structural types containing only other sendable types.
2727
2695
`Owned`
2728
2696
: Types of this kind do not contain any borrowed pointers;
2729
-
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
2697
+
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
2730
2698
`Copy`
2731
2699
: This kind includes all types that can be copied. All types with
2732
2700
sendable kind are copyable, as are managed boxes, managed closures,
2733
2701
trait types, and structural types built out of these.
2734
-
Types with destructors (types that implement `Drop`) can not implement `Copy`.
0 commit comments