async-safe-defer 0.1.2

Minimal async- and sync-capable `defer` crate
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented0 out of 9 items with examples
  • Size
  • Source code size: 15.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.21 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • rust-dd/async-safe-defer
    8 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dancixx

async-safe-defer

Minimal async- and sync-capable defer crate with:

  • ✅ async support
  • ✅ no unsafe code
  • no_std + alloc compatible
  • ✅ optional no_alloc mode
  • ✅ zero dependencies

Inspired by defer, but designed for embedded and async contexts.

Usage

Sync

use async_defer::defer;

fn main() {
    defer!(println!("cleanup"));
    println!("work");
}

Async

use async_defer::async_scope;

async_scope!(scope, {
    scope.defer(|| async { println!("async cleanup") });
    println!("async work");
}).await;

No-alloc

use async_defer::no_alloc::AsyncScopeNoAlloc;

fn task() -> Pin<Box<dyn Future<Output = ()> + 'static>> {
    Box::pin(async { println!("no_alloc") })
}

let mut scope = AsyncScopeNoAlloc::<2>::new();
scope.defer(task);
scope.run().await;