Skip to content

Commit 0cea272

Browse files
committed
chore: add readme
1 parent 44eb145 commit 0cea272

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# async-safe-defer
2+
3+
Minimal async- and sync-capable `defer` crate with:
4+
5+
- ✅ async support
6+
- ✅ no `unsafe` code
7+
-`no_std` + `alloc` compatible
8+
- ✅ optional `no_alloc` mode
9+
- ✅ zero dependencies
10+
11+
Inspired by [`defer`](https://crates.io/crates/defer), but designed for embedded and async contexts.
12+
13+
## Usage
14+
15+
### Sync
16+
```rust
17+
use async_defer::defer;
18+
19+
fn main() {
20+
defer!(println!("cleanup"));
21+
println!("work");
22+
}
23+
```
24+
25+
### Async
26+
```rust
27+
use async_defer::async_scope;
28+
29+
async_scope!(scope, {
30+
scope.defer(|| async { println!("async cleanup") });
31+
println!("async work");
32+
}).await;
33+
```
34+
35+
### No-alloc
36+
```rust
37+
use async_defer::no_alloc::AsyncScopeNoAlloc;
38+
39+
fn task() -> Pin<Box<dyn Future<Output = ()> + 'static>> {
40+
Box::pin(async { println!("no_alloc") })
41+
}
42+
43+
let mut scope = AsyncScopeNoAlloc::<2>::new();
44+
scope.defer(task);
45+
scope.run().await;
46+
```

0 commit comments

Comments
 (0)