@@ -19,20 +19,13 @@ enum MyEnum {
19
19
}
20
20
21
21
fn a_to_b (e : & mut MyEnum ) {
22
-
23
- // we mutably borrow `e` here. This precludes us from changing it directly
24
- // as in `*e = ...`, because the borrow checker won't allow it. Therefore
25
- // the assignment to `e` must be outside the `if let` clause.
26
- * e = if let MyEnum :: A { ref mut name , x : 0 } = * e {
27
-
22
+ if let MyEnum :: A { name , x : 0 } = e {
28
23
// this takes out our `name` and put in an empty String instead
29
24
// (note that empty strings don't allocate).
30
25
// Then, construct the new enum variant (which will
31
- // be assigned to `*e`, because it is the result of the `if let` expression).
32
- MyEnum :: B { name : mem :: take (name ) }
33
-
34
- // In all other cases, we return immediately, thus skipping the assignment
35
- } else { return }
26
+ // be assigned to `*e`).
27
+ * e = MyEnum :: B { name : mem :: take (name ) }
28
+ }
36
29
}
37
30
```
38
31
@@ -50,11 +43,11 @@ enum MultiVariateEnum {
50
43
51
44
fn swizzle (e : & mut MultiVariateEnum ) {
52
45
use MultiVariateEnum :: * ;
53
- * e = match * e {
46
+ * e = match e {
54
47
// Ownership rules do not allow taking `name` by value, but we cannot
55
48
// take the value out of a mutable reference, unless we replace it:
56
- A { ref mut name } => B { name : mem :: take (name ) },
57
- B { ref mut name } => A { name : mem :: take (name ) },
49
+ A { name } => B { name : mem :: take (name ) },
50
+ B { name } => A { name : mem :: take (name ) },
58
51
C => D ,
59
52
D => C
60
53
}
0 commit comments