Crate scopeguard_lite

Crate scopeguard_lite 

Source
Expand description

A lightweight way to defer execution of a block to the end of the scope, and to run code during an unwind.

This crate provides the defer! macro and Defer RAII guard.

This crate is extremely lightweight: it has no external dependencies or build scripts, and <150 LOC.

§Notes

§Drop Order

In Rust, local variables are always dropped in reverse declaration order.
ie. the following program prints 012:

defer! { print!("2"); }
defer! { print!("1"); }
print!("0");

That is to say, the first scopeguard you define in a scope is the one that runs last.

§Rust Version

The current MSRV is 1.61. While unlikely, it may increase in a future minor release.

Macros§

defer
Defers execution of the enclosed code until the end of scope. The code will run when the current scope ends, regardless of how that happens (panic, return, etc).

Structs§

Defer
Execute a closure on drop.