Re:The Pain of Real Linear Types in Rust
by stuhood on Tuesday May 09, 2017 @01:20PM
(#14301968)
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?...
[ Parent
| on HN ]
You could use something like Go's 'defer' statement to ensure 'close' is called before the current function returns.
Re:The Pain of Real Linear Types in Rust
by belovedeagle on Tuesday May 09, 2017 @01:51PM
(#14302327)
Which already exists in Rust in the form of... wait for it... the Drop trait. It's the same thing.
Re:The Pain of Real Linear Types in Rust
by matt_kantor on Tuesday May 09, 2017 @02:52PM
(#14302852)
The difference is that Go's `defer` is explicitly written out in the relevant scope, while Rust's `Drop` is implicit and defined elsewhere.
Re:The Pain of Real Linear Types in Rust
by steveklabnik on Tuesday May 09, 2017 @02:59PM
(#14302903)
There's a "scopeguard" crate that uses Drop to make it explicit.