3 ms·
This is a really interesting thought. In the presence of must-use types, you'd imagine that types with side effecting Drop impls (like files), would want to mig
by stuhood 9y ago
This is a really interesting thought. In the presence of must-use types, you'd imagine that types with side effecting Drop impls (like files), would want to migrate to eventually being used/consumed by a "close" method. But doing that safely in the presence of panics would require... exception handlers?...
- panic 9y agoYou could use something like Go's 'defer' statement to ensure 'close' is called before the current function returns.
- belovedeagle 9y agoWhich already exists in Rust in the form of... wait for it... the Drop trait. It's the same thing.
- matt_kantor 9y agoThe difference is that Go's `defer` is explicitly written out in the relevant scope, while Rust's `Drop` is implicit and defined elsewhere.
- steveklabnik 9y agoThere's a "scopeguard" crate that uses Drop to make it explicit.