Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
panic
· 9y ago · 0 comments
You could use something like Go's 'defer' statement to ensure 'close' is called before the current function returns.
Comments
[–]
belovedeagle
9y ago
Which already exists in Rust in the form of... wait for it... the Drop trait. It's the same thing.
[–]
matt_kantor
9y ago
The 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 ago
There's a "scopeguard" crate that uses Drop to make it explicit.