aboutsummaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2020-10-14 15:02:29 +0200
committerJeff Vander Stoep <jeffv@google.com>2020-10-14 15:04:30 +0200
commit3ba109e9da75e511590dfdb7da777cb9ec831812 (patch)
tree6d8e0d507a265081f57996a955cd03af311d3b71 /README.rst
parent6aa8348d575b2a2a24140727fa219a8a74f8b6a1 (diff)
downloadscopeguard-3ba109e9da75e511590dfdb7da777cb9ec831812.tar.gz
Import scopeguard 1.1.0
And add metadata files using the following command: get_rust_pkg.py --add3prf -v scopeguard-1.1.0 Test: none Change-Id: Iecb67802bbf006b68f25b6c7b73f16dce7a5de41
Diffstat (limited to 'README.rst')
-rw-r--r--README.rst103
1 files changed, 103 insertions, 0 deletions
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..019ffe7
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,103 @@
+
+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 / not on uwinding strategies requires linking to `std`.
+
+Requires Rust 1.20.
+
+
+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_all(b"test me\n").unwrap();
+ }
+
+Recent Changes
+--------------
+
+- 1.1.0
+
+ - Change macros (``defer!``, ``defer_on_success!`` and ``defer_on_unwind!``)
+ to accept statements. (by @konsumlamm)
+
+- 1.0.0
+
+ - Change the closure type from ``FnMut(&mut T)`` to ``FnOnce(T)``:
+ Passing the inner value by value instead of a mutable reference is a
+ breaking change, but allows the guard closure to consume it. (by @tormol)
+
+ - Add ``defer_on_success!{}``, ``guard_on_success()`` and ``OnSuccess``
+ strategy, which triggers when scope is exited *without* panic. It's the
+ opposite to ``OnUnwind`` / ``guard_on_unwind()`` / ``defer_on_unwind!{}``.
+
+ - Add ``ScopeGuard::into_inner()``, which "defuses" the guard and returns the
+ guarded value. (by @tormol)
+
+ - Implement ``Sync`` for guards with non-``Sync`` closures.
+
+ - Require Rust 1.20
+
+- 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 ``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!()``