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 _binary move expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) followed by a left-pointing
1735
-
arrow (`<-`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
1736
-
1737
-
Evaluating a move expression causes, as a side effect,
1738
-
the rvalue to be *moved* into the lvalue.
1739
-
If the rvalue was itself an lvalue, it must be a local variable,
1740
-
as it will be de-initialized in the process.
1741
-
1742
-
Evaluating a move expression does not change reference counts,
1743
-
nor does it cause a deep copy of any owned structure pointed to by the moved rvalue.
1744
-
Instead, the move expression represents an indivisible *transfer of ownership*
1745
-
from the right-hand-side to the left-hand-side of the expression.
1746
-
No allocation or destruction is entailed.
1747
-
1748
-
An example of three different move expressions:
1749
-
1750
-
~~~~~~~~
1751
-
# let mut x = &[mut 0];
1752
-
# let a = &[mut 0];
1753
-
# let b = 0;
1754
-
# let y = {mut z: 0};
1755
-
# let c = 0;
1756
-
# let i = 0;
1757
-
1758
-
x <- a;
1759
-
x[i] <- b;
1760
-
y.z <- c;
1761
-
~~~~~~~~
1762
-
1763
1731
#### Swap expressions
1764
1732
1765
1733
A _swap expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) followed by a bi-directional arrow (`<->`) and another [lvalue](#lvalues-rvalues-and-temporaries).
@@ -1792,21 +1760,15 @@ y.z <-> b.c;
1792
1760
An _assignment expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) expression followed by an
1793
1761
equals sign (`=`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
1794
1762
1795
-
Evaluating an assignment expression is equivalent to evaluating a [binary move
1796
-
expression](#binary-move-expressions) applied to a [unary copy
1797
-
expression](#unary-copy-expressions). For example, the following two
1798
-
expressions have the same effect:
1763
+
Evaluating an assignment expression copies the expression on the right-hand side and stores it in the location on the left-hand side.
1799
1764
1800
1765
~~~~
1801
1766
# let mut x = 0;
1802
1767
# let y = 0;
1803
1768
1804
1769
x = y;
1805
-
x <- copy y;
1806
1770
~~~~
1807
1771
1808
-
The former is just more terse and familiar.
1809
-
1810
1772
#### Compound assignment expressions
1811
1773
1812
1774
The `+`, `-`, `*`, `/`, `%`, `&`, `|`, `^`, `<<`, and `>>`
0 commit comments