Skip to content

Commit

Permalink
Mention that you're not allowed to partially move Drop types
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcsible committed Dec 16, 2024
1 parent 7640633 commit d2f9fb1
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit d2f9fb1

Please sign in to comment.