1
+ <!--
1
2
# Partial moves
3
+ -->
4
+ # 部分的ムーブ
2
5
6
+ <!--
3
7
Within the [destructuring] of a single variable, both `by-move` and
4
8
`by-reference` pattern bindings can be used at the same time. Doing
5
9
this will result in a _partial move_ of the variable, which means
6
10
that parts of the variable will be moved while other parts stay. In
7
11
such a case, the parent variable cannot be used afterwards as a
8
12
whole, however the parts that are only referenced (and not moved)
9
13
can still be used.
14
+ -->
15
+ 1つの変数の [ デストラクト] の中で、 ` ムーブ ` と ` 参照 ` の両方のパターンバインディングを同時に使用することができます。両方を使用すると、変数の一部がムーブされ、他の部分が参照として残るという変数の部分的ムーブが発生した状態になります。変数の部分的ムーブが発生すると親変数はその後使用できませんが、参照されているだけの部分(ムーブされていない部分)は使用することができます。
16
+
17
+ [ デストラクト ] : ../../flow_control/match/destructuring.md
10
18
11
19
``` rust,editable
12
20
fn main() {
@@ -22,20 +30,30 @@ fn main() {
22
30
};
23
31
24
32
// `name` is moved out of person, but `age` is referenced
33
+ // `name` は person からムーブしたが、 `age` は参照されている
25
34
let Person { name, ref age } = person;
26
35
27
36
println!("The person's age is {}", age);
28
37
29
38
println!("The person's name is {}", name);
30
39
31
40
// Error! borrow of partially moved value: `person` partial move occurs
41
+ // エラー!部分的ムーブした値の借用:`person` では部分的ムーブが発生している
32
42
//println!("The person struct is {:?}", person);
33
43
34
44
// `person` cannot be used but `person.age` can be used as it is not moved
45
+ // `person` は使用できないが、 `person.age` はムーブしていないので使用できる
35
46
println!("The person's age from person struct is {}", person.age);
36
47
}
37
48
```
49
+ <!--
38
50
### See also:
51
+ -->
52
+ ### 参照
53
+
54
+ <!--
39
55
[destructuring][destructuring]
56
+ -->
57
+ [ デストラクト] [ destructuring ]
40
58
41
- [ destructuring ] : ../../flow_control/match/destructuring.md
59
+ [ destructuring ] : ../../flow_control/match/destructuring.md
0 commit comments