forked from mirrors/gecko-dev
Update rand version in u2fhid and xpcom Differential Revision: https://phabricator.services.mozilla.com/D31669 --HG-- rename : third_party/rust/scopeguard/.cargo-checksum.json => third_party/rust/scopeguard-0.3.2/.cargo-checksum.json rename : third_party/rust/scopeguard/Cargo.toml => third_party/rust/scopeguard-0.3.2/Cargo.toml rename : third_party/rust/scopeguard/README.rst => third_party/rust/scopeguard-0.3.2/README.rst rename : third_party/rust/scopeguard/examples/readme.rs => third_party/rust/scopeguard-0.3.2/examples/readme.rs rename : third_party/rust/scopeguard/src/lib.rs => third_party/rust/scopeguard-0.3.2/src/lib.rs extra : moz-landing-system : lando
27 lines
492 B
Rust
27 lines
492 B
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();
|
|
}
|
|
|
|
fn main() {
|
|
f();
|
|
g();
|
|
}
|