Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/scope/move/partial_move.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ this will result in a _partial move_ of the variable, which means
that parts of the variable will be moved while other parts stay. In
such a case, the parent variable cannot be used afterwards as a
whole, however the parts that are only referenced (and not moved)
can still be used.
can still be used. Note that types that implement the
[`Drop` trait][droptrait] cannot be partially moved from, because
its `drop` method would use it afterwards as a whole.


```rust,editable
fn main() {
Expand All @@ -16,6 +19,14 @@ fn main() {
age: Box<u8>,
}

// Error! cannot move out of a type which implements the `Drop` trait
//impl Drop for Person {
// fn drop(&mut self) {
// println!("Dropping the person struct {:?}", self)
// }
//}
// TODO ^ Try uncommenting these lines

let person = Person {
name: String::from("Alice"),
age: Box::new(20),
Expand Down Expand Up @@ -47,4 +58,5 @@ not be required as the definition of `age` would copy the data from

[destructuring][destructuring]

[droptrait]: ../../trait/drop.md
[destructuring]: ../../flow_control/match/destructuring.md
Loading