# Re-use struct fields on drop; was: Drop(&mut self) vs. drop(self)

**URL:** https://internals.rust-lang.org/t/re-use-struct-fields-on-drop-was-drop-mut-self-vs-drop-self/8594
**Category:** language design
**Created:** [October 17, 2018, 10:16am UTC](https://internals.rust-lang.org/t/re-use-struct-fields-on-drop-was-drop-mut-self-vs-drop-self/8594 "2018-10-17T10:16:36Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![literda](https://avatars.discourse-cdn.com/v4/letter/l/96bed5/32.png) [@literda](https://internals.rust-lang.org/u/literda)
#### Post date: [October 17, 2018, 12:10pm UTC](https://internals.rust-lang.org/t/re-use-struct-fields-on-drop-was-drop-mut-self-vs-drop-self/8594/5 "2018-10-17T12:10:51Z")

</div>

> [@kornel](#):
>
> There are two ways you can “rescue” fields from an object being dropped: `Option.take()` (take the object and replace it with nothing), or `mem::replace()` (take the object and replace it with another one, usually a dummy one).

I'm mostly using the `Option`-way currently, but as far as I can see, both these ways have drawbacks:

With the `Option` method I pay a runtime cost every time I want to access a member of that struct during the "regular" time of life of that struct. Also, there are more possible error-paths.

The `mem::replace` method is in a way just the `Option` method in disguise: The value that I create to replace the precious value must be created at that spot in the code, which usually means that it is some disfunctional state and kind of a `None` anyway (think a unopened file). The problem here is that, if it is possible to construct such a null-like value, then the member functions of the struct typically have to deal with that possibility too and check before each access, which is like doing `if let Some(x) ...`.

Ultimately, I want to make useless/disfunctional state irrepresentable, but both the `Option` as well as the `mem::replace` method require a useless/disfunctional state to be possible.

With [this method](https://internals.rust-lang.org/t/drop-mut-self-vs-drop-self/8594/3) I can avoid disfunctional state, and re-use the fields after drop.

---

_[View the full topic](https://internals.rust-lang.org/t/re-use-struct-fields-on-drop-was-drop-mut-self-vs-drop-self/8594)._
