File tree 1 file changed +13
-1
lines changed 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ this will result in a _partial move_ of the variable, which means
6
6
that parts of the variable will be moved while other parts stay. In
7
7
such a case, the parent variable cannot be used afterwards as a
8
8
whole, however the parts that are only referenced (and not moved)
9
- can still be used.
9
+ can still be used. Note that types that implement the
10
+ [ ` Drop ` trait] [ droptrait ] cannot be partially moved from, because
11
+ its ` drop ` method would use it afterwards as a whole.
12
+
10
13
11
14
``` rust,editable
12
15
fn main() {
@@ -16,6 +19,14 @@ fn main() {
16
19
age: Box<u8>,
17
20
}
18
21
22
+ // Error! cannot move out of a type which implements the `Drop` trait
23
+ //impl Drop for Person {
24
+ // fn drop(&mut self) {
25
+ // println!("Dropping the person struct {:?}", self)
26
+ // }
27
+ //}
28
+ // TODO ^ Try uncommenting these lines
29
+
19
30
let person = Person {
20
31
name: String::from("Alice"),
21
32
age: Box::new(20),
@@ -47,4 +58,5 @@ not be required as the definition of `age` would copy the data from
47
58
48
59
[ destructuring] [ destructuring ]
49
60
61
+ [ droptrait ] : ../../trait/drop.md
50
62
[ destructuring ] : ../../flow_control/match/destructuring.md
You can’t perform that action at this time.
0 commit comments