File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 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
66that parts of the variable will be moved while other parts stay. In
77such a case, the parent variable cannot be used afterwards as a
88whole, 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+
1013
1114``` rust,editable
1215fn main() {
@@ -16,6 +19,14 @@ fn main() {
1619 age: Box<u8>,
1720 }
1821
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+
1930 let person = Person {
2031 name: String::from("Alice"),
2132 age: Box::new(20),
@@ -47,4 +58,5 @@ not be required as the definition of `age` would copy the data from
4758
4859[ destructuring] [ destructuring ]
4960
61+ [ droptrait ] : ../../trait/drop.md
5062[ destructuring ] : ../../flow_control/match/destructuring.md
You can’t perform that action at this time.
0 commit comments