| Crates.io | async-safe-defer |
| lib.rs | async-safe-defer |
| version | 0.1.2 |
| created_at | 2025-04-12 10:05:12.927653+00 |
| updated_at | 2025-04-12 10:15:00.3533+00 |
| description | Minimal async- and sync-capable `defer` crate |
| homepage | https://github.com/rust-dd/async-safe-defer |
| repository | https://github.com/rust-dd/async-safe-defer |
| max_upload_size | |
| id | 1630786 |
| size | 16,218 |
Minimal async- and sync-capable defer crate with:
unsafe codeno_std + alloc compatibleno_alloc modeInspired by defer, but designed for embedded and async contexts.
use async_defer::defer;
fn main() {
defer!(println!("cleanup"));
println!("work");
}
use async_defer::async_scope;
async_scope!(scope, {
scope.defer(|| async { println!("async cleanup") });
println!("async work");
}).await;
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;