#scope #defer #resources #procedure #exit #closures #leave

scope-exit

The util to call procedure when exit current scope. scope exit. like defer in go.

2 unstable releases

0.2.0 Jan 15, 2024
0.1.0 Nov 15, 2023

#1736 in Rust patterns

Apache-2.0

4KB
76 lines

Scope Exit utils

Will call closure when leave current scope. Useful to release some resource got from FFI.

e.g. Call c file API

fn test() {
    let fp = fopen("test.txt");
    scope_exit!(fclose(fp));
    // will call `fclose` by RAII
}

No runtime deps