Crates.io | rdefer |
lib.rs | rdefer |
version | 1.0.0 |
source | src |
created_at | 2023-06-02 12:16:09.858938 |
updated_at | 2023-06-02 12:16:09.858938 |
description | A Rust crate providing go like defer functionality in both sync and async contexts. |
homepage | |
repository | |
max_upload_size | |
id | 880777 |
size | 11,078 |
A Rust crate providing defer functionality for both synchronous and asynchronous code.
use rdefer::defer;
let _d = defer!({
println!("This will be printed last");
});
println!("This will be printed first");
This feature is behind the async feature flag.
To use this feature, add rdefer to your Cargo.toml with the async feature enabled:
[dependencies]
rdefer = { version = "*", features = ["async"] }
Then you can use it as follows:
use rdefer::{async_defer, exec_before_defer};
use std::sync::Arc;
let defer = async_defer!(2, async {
println!("This will be printed last");
});
exec_before_defer!(defer, || println!("This will be printed first"));
exec_before_defer!(defer, || println!("This will be printed second"));