Skip to content

Rust defer crate with both sync & async functionality

License

Notifications You must be signed in to change notification settings

alexthe2/rdefer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rdefer

A Rust crate providing defer functionality for both synchronous and asynchronous code.

Usage

Synchronous Defer

use rdefer::defer;

let _d = defer!({
    println!("This will be printed last");
});
println!("This will be printed first");

Asynchronous Defer (Feature gated)

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"));

About

Rust defer crate with both sync & async functionality

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages