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