Crates.io | drop_guard |
lib.rs | drop_guard |
version | 0.3.0 |
source | src |
created_at | 2017-07-13 07:56:02.561946 |
updated_at | 2021-11-24 16:45:09.163427 |
description | The drop_guard crate enables you to implement the Drop trait on any type. So you can run a closure on any value running out of scope. |
homepage | |
repository | https://github.com/dns2utf8/drop_guard |
max_upload_size | |
id | 23195 |
size | 12,237 |
A RAII that executes you function whenever the wrapped object gets dropped.
Joining threads when they fall out of scope:
extern crate drop_guard;
use drop_guard::DropGuard;
use std::thread::{spawn, sleep};
use std::time::guard;
fn main() {
let _ = guard(spawn(move || {
sleep(Duration::from_secs(2));
println!("println! from thread");
})
, |join_handle| join_handle.join().unwrap());
println!("Waiting for thread ...");
}
Feel free to run the included examples:
cargo run --example drop
cargo run --example rainbow
cargo run --example thread
cargo run --example threadpool
Contributions are very welcome. Feel free to bring your own ideas or continue one of these:
Licensed under either of
at your discression.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.