2016-02-23 15:15:58 -08:00
2015-09-03 16:46:02 +02:00
2015-09-03 16:54:09 +02:00
2015-04-30 14:01:02 +02:00
2015-04-30 14:01:02 +02:00
2016-02-12 22:33:49 +01:00

scopeguard
==========

Rust crate for a convenient RAII scope guard.

Please read the `API documentation here`__

__ http://bluss.github.io/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
----------

::

    extern crate scopeguard;

    use scopeguard::guard;

    fn f() {
        let _defer = guard((), |_| {
            println!("Called at return or panic");
        });
        panic!();
    }

    fn g() {
        let f = File::create("newfile.txt").unwrap();
        let mut file = guard(f, |f| {
            // write file at return or panic
            f.sync_all();
        });
        file.write("testme\n");
    }
S
Description
一个方便的RAII作用域保护库,当超出作用域时,将运行指定的闭包,即使代码即将panic
Readme 198 KiB
Languages
Rust 100%