#panic #scope-guard #defer

scopeguard

A RAII scope guard that will run a given closure when it goes out of scope, even if the code between panics (assuming unwinding panic). Defines the macros defer! and defer_on_unwind!; the latter only runs if the scope is extited through unwinding on panic

8 releases

0.3.3 Oct 13, 2017
0.3.2 Jan 21, 2017
0.3.1 Dec 11, 2016
0.2.0 Jun 23, 2016
0.1.0 Apr 30, 2015

#2 in Rust patterns

Download history 31090/week @ 2018-09-05 43183/week @ 2018-09-12 44226/week @ 2018-09-19 41827/week @ 2018-09-26 43870/week @ 2018-10-03 43111/week @ 2018-10-10 45877/week @ 2018-10-17 42077/week @ 2018-10-24 51121/week @ 2018-10-31 49576/week @ 2018-11-07 49608/week @ 2018-11-14 49424/week @ 2018-11-21 42912/week @ 2018-11-28

112,505 downloads per month
Used in 2,327 crates (17 directly)

MIT/Apache

15KB
175 lines

scopeguard

Rust crate for a convenient RAII scope guard that will run a given closure when it goes out of scope, even if the code between panics (assuming unwinding panic).

The defer! macro and guard are no_std compatible (require only core), but the on unwinding strategy requires linking to std.

Requires Rust 1.11.

Please read the API documentation here

build_status crates

How to use

Recent Changes

  • 0.3.3

    • Use #[inline] on a few more functions by @stjepang (#14)

    • Add examples to crate documentation

  • 0.3.2

    • Add crate categories

  • 0.3.1

    • Add defer_on_unwind!, Strategy trait

    • Rename GuardScopeGuard

    • Add ScopeGuard::with_strategy.

    • ScopeGuard now implements Debug.

    • Require Rust 1.11

  • 0.2.0

    • Require Rust 1.6

    • Use no_std unconditionally

    • No other changes

  • 0.1.2

    • Add macro defer!()

No runtime deps