gecko-dev/third_party/rust/scopeguard
Nathan Froyd b93bf873ba Bug 1502964 - part 2 - update winapi to froydnj/winapi-rs#aarch64; r=ted.mielczarek 2018-11-02 10:56:08 -04:00
..
examples
src
.cargo-checksum.json Bug 1502964 - part 2 - update winapi to froydnj/winapi-rs#aarch64; r=ted.mielczarek 2018-11-02 10:56:08 -04:00
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.rst

README.rst

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`__

__ https://docs.rs/scopeguard/

|build_status|_ |crates|_

.. |build_status| image:: https://travis-ci.org/bluss/scopeguard.svg
.. _build_status: https://travis-ci.org/bluss/scopeguard

.. |crates| image:: http://meritbadge.herokuapp.com/scopeguard
.. _crates: https://crates.io/crates/scopeguard

How to use
----------

.. code:: rust

    #[macro_use(defer)] extern crate scopeguard;

    use scopeguard::guard;

    fn f() {
        defer!(println!("Called at return or panic"));
        panic!();
    }

    use std::fs::File;
    use std::io::Write;

    fn g() {
        let f = File::create("newfile.txt").unwrap();
        let mut file = guard(f, |f| {
            // write file at return or panic
            let _ = f.sync_all();
        });
        // Access the file through the scope guard itself
        file.write(b"test me\n").unwrap();
    }

Recent Changes
--------------

- 0.3.2

  - Add crate categories

- 0.3.1

  - Add ``defer_on_unwind!``, ``Strategy`` trait
  - Rename ``Guard`` → ``ScopeGuard``
  - 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!()``