Skip to content

Commit

Permalink
Try a more explicit example for partial move destructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 7, 2019
1 parent 663b0fb commit a5b0281
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ loop {
moved = ShowOnDrop("Drops when moved");
// drops now, but is then uninitialized
moved;

// Uninitialized does not drop.
let uninitialized: ShowOnDrop;
// Only first element drops
let mut partially_initialized = (ShowOnDrop("one"), ShowOnDrop("two"));
core::mem::forget(partially_initialized.1);

// After a partial move, only the remaining fields are dropped.
let mut partial_move = (ShowOnDrop("first"), ShowOnDrop("forgotten"));
// Perform a partial move, leaving only `partial_move.0` initialized.
core::mem::forget(partial_move.1);
// When partial_move's scope ends, only the first field is dropped.
}
```

Expand Down

0 comments on commit a5b0281

Please sign in to comment.