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
@@ -1558,6 +1584,7 @@ When no mutability is specified, the vector is immutable.
1558
1584
~~~~
1559
1585
[1, 2, 3, 4];
1560
1586
["a", "b", "c", "d"];
1587
+
[0, ..128]; // vector with 128 zeros
1561
1588
[mut 0u8, 0u8, 0u8, 0u8];
1562
1589
~~~~
1563
1590
@@ -1889,7 +1916,7 @@ let x: int = add(1, 2);
1889
1916
1890
1917
~~~~~~~~{.abnf .gram}
1891
1918
ident_list : [ ident [ ',' ident ]* ] ? ;
1892
-
lambda_expr : '|' ident_list '| expr ;
1919
+
lambda_expr : '|' ident_list '|' expr ;
1893
1920
~~~~~~~~
1894
1921
1895
1922
A _lambda expression_ (a.k.a. "anonymous function expression") defines a function and denotes it as a value,
@@ -2170,17 +2197,6 @@ When matching fields of a record,
2170
2197
the fields being matched are specified first,
2171
2198
then a placeholder (`_`) represents the remaining fields.
2172
2199
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
-
2184
2200
~~~~
2185
2201
# type options = {choose: bool, size: ~str};
2186
2202
# type player = {player: ~str, stats: (), options: options};
@@ -2212,6 +2228,22 @@ fn main() {
2212
2228
}
2213
2229
~~~~
2214
2230
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
+
2215
2247
Multiple match patterns may be joined with the `|` operator. A
2216
2248
range of values may be specified with `..`. For example:
2217
2249
@@ -2694,11 +2726,12 @@ The kinds are:
2694
2726
structural types containing only other sendable types.
2695
2727
`Owned`
2696
2728
: Types of this kind do not contain any borrowed pointers;
2697
-
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
2729
+
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
2698
2730
`Copy`
2699
2731
: This kind includes all types that can be copied. All types with
2700
2732
sendable kind are copyable, as are managed boxes, managed closures,
2701
2733
trait types, and structural types built out of these.
2734
+
Types with destructors (types that implement `Drop`) can not implement `Copy`.
0 commit comments