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
Copy file name to clipboardExpand all lines: src/expressions/operator-expr.md
+18-30Lines changed: 18 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -428,20 +428,15 @@ assert_eq!(values[1], 3);
428
428
429
429
An *assignment expression* moves a value into a specified place.
430
430
431
-
An assignment expression consists of a [mutable][assignee expression], the
432
-
*assignee operand*, followed by an equals sign (`=`) and a [value expression],
433
-
the *assigned value operand*. In its most basic form, an assignee expression is
434
-
a [place expression], and we discuss this case first. The more general case of
435
-
destructuring assignment is discussed below, but this case always decomposes
436
-
into sequential assignments to place expressions, which may be considered the
437
-
more fundamental case.
431
+
An assignment expression consists of a [mutable][assignee expression], the *assignee operand*, followed by an equals sign (`=`) and a [value expression], the *assigned value operand*.
432
+
In its most basic form, an assignee expression is a [place expression], and we discuss this case first.
433
+
The more general case of destructuring assignment is discussed below, but this case always decomposes into sequential assignments to place expressions, which may be considered the more fundamental case.
438
434
439
435
### Basic assignments
440
436
441
-
Evaluating assignment expressions begins by evaluating its operands. The
442
-
assigned value operand is evaluated first, followed by the assignee expression.
443
-
(For destructuring assignment, subexpressions of the assignee expression are
444
-
evaluated left-to-right.)
437
+
Evaluating assignment expressions begins by evaluating its operands.
438
+
The assigned value operand is evaluated first, followed by the assignee expression.
439
+
For destructuring assignment, subexpressions of the assignee expression are evaluated left-to-right.
445
440
446
441
> **Note**: This is different than other expressions in that the right operand is evaluated before the left one.
447
442
@@ -460,29 +455,25 @@ x = y;
460
455
461
456
### Destructuring assignments
462
457
463
-
Destructuring assignment is a counterpart to destructuring pattern matches for
464
-
variable declaration, permitting assignment to complex values, such as tuples or
465
-
structs. For instance, we may swap two mutable variables:
458
+
Destructuring assignment is a counterpart to destructuring pattern matches for variable declaration, permitting assignment to complex values, such as tuples or structs.
459
+
For instance, we may swap two mutable variables:
466
460
467
-
```rust,ignore
461
+
```rust
468
462
let (muta, mutb) = (0, 1);
469
463
// Swap `a` and `b` using destructuring assignment.
470
464
(b, a) = (a, b);
471
465
```
472
466
473
-
In contrast to destructuring declarations using `let`, patterns may not appear
474
-
on the left-hand side of an assignment due to syntactic ambiguities. Instead, a
475
-
group of expressions that correspond to patterns are designated to be [assignee
476
-
expressions][assignee expression], and permitted on the left-hand side of an
477
-
assignment. Assignee expressions are then desugared to pattern matches followed
478
-
by sequential assignment. The desugared patterns must be irrefutable: in
479
-
particular, this means that only slice patterns whose length is known at
480
-
compile-time, and the trivial slice `[..]`, are permitted for destructuring
481
-
assignment.
467
+
In contrast to destructuring declarations using `let`, patterns may not appear on the left-hand side of an assignment due to syntactic ambiguities.
468
+
Instead, a group of expressions that correspond to patterns are designated to be [assignee expressions][assignee expression], and permitted on the left-hand side of an assignment.
469
+
Assignee expressions are then desugared to pattern matches followed by sequential assignment.
470
+
The desugared patterns must be irrefutable: in particular, this means that only slice patterns whose length is known at compile-time, and the trivial slice `[..]`, are permitted for destructuring assignment.
482
471
483
472
The desugaring method is straightforward, and is illustrated best by example.
484
473
485
-
```rust,ignore
474
+
```rust
475
+
# structStruct { x:u32, y:u32 }
476
+
# let (muta, mutb) = (0, 0);
486
477
(a, b) = (3, 4);
487
478
488
479
[a, b] = [3, 4];
@@ -510,12 +501,9 @@ Struct { x: a, y: b } = Struct { x: 3, y: 4};
510
501
}
511
502
```
512
503
513
-
Identifiers are not forbidden from being used multiple times in a single
514
-
assignee expression.
504
+
Identifiers are not forbidden from being used multiple times in a single assignee expression.
515
505
516
-
[Underscore expressions][_UnderscoreExpression_] and empty [range
517
-
expressions][_RangeExpression_] may be used to ignore certain values, without
518
-
binding them.
506
+
[Underscore expressions][_UnderscoreExpression_] and empty [range expressions][_RangeExpression_] may be used to ignore certain values, without binding them.
519
507
520
508
Note that default binding modes do not apply for the desugared expression.
0 commit comments