• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H03-May-2022-2819

src/H03-May-2022-410175

.cargo-checksum.jsonH A D03-May-202289 11

.gitignoreH A D08-Dec-201618 32

.travis.ymlH A D13-Oct-2017287 2016

Cargo.tomlH A D01-Jan-19701.1 KiB2926

Cargo.toml.orig-cargoH A D13-Oct-2017652 2720

LICENSE-APACHEH A D08-Dec-201610.6 KiB202169

LICENSE-MITH A D08-Dec-20161 KiB2622

README.rstH A D13-Oct-20171.7 KiB8253

README.rst

1
2scopeguard
3==========
4
5Rust crate for a convenient RAII scope guard that will run a given closure when
6it goes out of scope, even if the code between panics (assuming unwinding panic).
7
8The `defer!` macro and `guard` are `no_std` compatible (require only core),
9but the on unwinding strategy requires linking to `std`.
10
11Requires Rust 1.11.
12
13
14Please read the `API documentation here`__
15
16__ https://docs.rs/scopeguard/
17
18|build_status|_ |crates|_
19
20.. |build_status| image:: https://travis-ci.org/bluss/scopeguard.svg
21.. _build_status: https://travis-ci.org/bluss/scopeguard
22
23.. |crates| image:: http://meritbadge.herokuapp.com/scopeguard
24.. _crates: https://crates.io/crates/scopeguard
25
26How to use
27----------
28
29.. code:: rust
30
31    #[macro_use(defer)] extern crate scopeguard;
32
33    use scopeguard::guard;
34
35    fn f() {
36        defer!(println!("Called at return or panic"));
37        panic!();
38    }
39
40    use std::fs::File;
41    use std::io::Write;
42
43    fn g() {
44        let f = File::create("newfile.txt").unwrap();
45        let mut file = guard(f, |f| {
46            // write file at return or panic
47            let _ = f.sync_all();
48        });
49        // Access the file through the scope guard itself
50        file.write(b"test me\n").unwrap();
51    }
52
53Recent Changes
54--------------
55
56- 0.3.3
57
58  - Use ``#[inline]`` on a few more functions by @stjepang (#14)
59  - Add examples to crate documentation
60
61- 0.3.2
62
63  - Add crate categories
64
65- 0.3.1
66
67  - Add ``defer_on_unwind!``, ``Strategy`` trait
68  - Rename ``Guard`` → ``ScopeGuard``
69  - Add ``ScopeGuard::with_strategy``.
70  - ``ScopeGuard`` now implements ``Debug``.
71  - Require Rust 1.11
72
73- 0.2.0
74
75  - Require Rust 1.6
76  - Use `no_std` unconditionally
77  - No other changes
78
79- 0.1.2
80
81  - Add macro ``defer!()``
82