Skip to main content


Man, I wish Rust had the 'defer' keyword 😞
Wait...

🦀 **scopeguard**: A Rust library for a convenient RAII scope guard.

🌀 Has a defer! macro.

🔥 Runs a closure on scope exit, even if a panic occurs.

⭐ GitHub: github.com/bluss/scopeguard

#rustlang #library #defer #scope #raii #guard #programming #pattern #opensource

in reply to Orhun Parmaksız 👾

this is less useful in Rust though because of borrow checker. You need interior mutability to really make use of that because you cannot call any method that takes ownership/mutable references in either defer or the normal scope.

Unless you write a proc macro wrapping the entire function that rewrites all exit points (including panics) to include the deferred action?

This entry was edited (2 weeks ago)