Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
examples/ | H | 03-May-2022 | - | 28 | 19 | |
src/ | H | 03-May-2022 | - | 410 | 175 | |
.cargo-checksum.json | H A D | 03-May-2022 | 89 | 1 | 1 | |
.gitignore | H A D | 08-Dec-2016 | 18 | 3 | 2 | |
.travis.yml | H A D | 13-Oct-2017 | 287 | 20 | 16 | |
Cargo.toml | H A D | 01-Jan-1970 | 1.1 KiB | 29 | 26 | |
Cargo.toml.orig-cargo | H A D | 13-Oct-2017 | 652 | 27 | 20 | |
LICENSE-APACHE | H A D | 08-Dec-2016 | 10.6 KiB | 202 | 169 | |
LICENSE-MIT | H A D | 08-Dec-2016 | 1 KiB | 26 | 22 | |
README.rst | H A D | 13-Oct-2017 | 1.7 KiB | 82 | 53 |
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