]>
Commit | Line | Data |
---|---|---|
85aaf69f SL |
1 | % Destructors |
2 | ||
3 | Unlike constructors, destructors in Rust have a special status: they are added | |
4 | by implementing `Drop` for a type, and they are automatically invoked as values | |
5 | go out of scope. | |
6 | ||
7 | > **[FIXME]** This section needs to be expanded. | |
8 | ||
9 | ### Destructors should not fail. [FIXME: needs RFC] | |
10 | ||
bd371182 | 11 | Destructors are executed on thread failure, and in that context a failing |
85aaf69f SL |
12 | destructor causes the program to abort. |
13 | ||
14 | Instead of failing in a destructor, provide a separate method for checking for | |
15 | clean teardown, e.g. a `close` method, that returns a `Result` to signal | |
16 | problems. | |
17 | ||
18 | ### Destructors should not block. [FIXME: needs RFC] | |
19 | ||
20 | Similarly, destructors should not invoke blocking operations, which can make | |
21 | debugging much more difficult. Again, consider providing a separate method for | |
22 | preparing for an infallible, nonblocking teardown. |