зеркало из https://github.com/mozilla/gecko-dev.git
d3f4d3cc1c
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 |
||
---|---|---|
.. | ||
readme.rs |
readme.rs
#[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(); }