Directs developers to implement AsyncDropGuard for correct asynchronous teardown of network handles and background tasks.
Install
mkdir -p .claude/skills/async-drop && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3340" && unzip -o skill.zip -d .claude/skills/async-drop && rm skill.zipInstalls to .claude/skills/async-drop
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Guide to the AsyncDrop pattern for async cleanup in Rust. Use when working with AsyncDropGuard, implementing AsyncDrop trait, or handling async resource cleanup.Key capabilities
- →Wrap values in AsyncDropGuard
- →Implement the AsyncDrop trait
- →Call async_drop() explicitly
- →Use the with_async_drop_2! macro for automatic cleanup
- →Delegate async_drops for types with guard members
How it works
The AsyncDrop pattern wraps values in an AsyncDropGuard, requiring explicit async_drop().await calls for asynchronous cleanup, or uses a macro for automatic cleanup on scope exit.
Inputs & outputs
When to use async-drop
- →Implementing async cleanup for network connections
- →Handling resource teardown in async tasks
- →Avoiding memory leaks in async code
About this skill
AsyncDrop Pattern Guide
The AsyncDrop pattern enables async cleanup for types that hold resources requiring asynchronous teardown (network connections, file handles, background tasks, etc.).
Core Concept
Rust's Drop trait is synchronous, but sometimes cleanup needs to be async. The AsyncDrop pattern solves this by:
- Wrapping values in
AsyncDropGuard<T> - Requiring explicit
async_drop().awaitcalls - Panicking if cleanup is forgotten
Quick Reference
// Creating
let mut guard = AsyncDropGuard::new(my_value);
// Using (transparent via Deref)
guard.do_something();
// Cleanup (REQUIRED before dropping)
guard.async_drop().await?;
The AsyncDrop Trait
#[async_trait]
pub trait AsyncDrop {
type Error: Debug;
async fn async_drop_impl(&mut self) -> Result<(), Self::Error>;
}
Essential Rules
| Rule | Description |
|---|---|
| Always call async_drop() | Every AsyncDropGuard must have async_drop() called |
| Factory methods return guards | fn new() -> AsyncDropGuard<Self>, never plain Self |
| Types with guard members impl AsyncDrop | Delegate to member async_drops |
| Use the macro when possible | with_async_drop_2! handles cleanup automatically |
| Panics are exceptions | It's OK to skip async_drop on panic paths |
The with_async_drop_2! Macro
Automatically calls async_drop() on scope exit:
let resource = get_resource().await?;
with_async_drop_2!(resource, {
// Use resource here
resource.do_work().await?;
Ok(result)
})
Additional References
- patterns.md - Implementation patterns and examples
- gotchas.md - Common mistakes and how to avoid them
- helpers.md - Helper types (AsyncDropArc, AsyncDropHashMap, etc.)
Location
Implementation: crates/utils/src/async_drop/
When not to use it
- →When cleanup does not need to be asynchronous
- →When a panic occurs, as skipping async_drop is acceptable
Limitations
- →Cleanup must be explicitly called or handled by a macro
- →Panicking can bypass cleanup logic
How it compares
This pattern provides a structured way to perform asynchronous cleanup, unlike Rust's synchronous Drop trait, which cannot handle async operations directly.
Compared to similar skills
async-drop side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| async-drop (this skill) | 1 | 7mo | Review | Intermediate |
| implementing-cards | 7 | 2mo | Review | Advanced |
| write-rust-tests | 9 | 5mo | No flags | Intermediate |
| rust-errors | 5 | 1mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by cryfs
View all by cryfs →You might also like
implementing-cards
bcollazo
Fill out the implementation of effects of different attacks, abilities, and trainer cards in this Pokemon TCG Pocket engine codebase.
write-rust-tests
RediSearch
Write Rust tests to verify correctness of Rust code.
rust-errors
EpicenterHQ
Rust to TypeScript error handling patterns for Tauri apps. Use when defining Rust errors that will be passed to TypeScript, handling Tauri command errors, or creating discriminated union error types.
write-script-rust
windmill-labs
MUST use when writing Rust scripts.
rust-pro
vudovn
Master Rust 1.75+ with modern async patterns, advanced type system features, and production-ready systems programming. Expert in the latest Rust ecosystem including Tokio, axum, and cutting-edge crates. Use PROACTIVELY for Rust development, performance optimization, or systems programming.
rust-router
actionbook
CRITICAL: Use for ALL Rust questions including errors, design, and coding. HIGHEST PRIORITY for: 比较, 对比, compare, vs, versus, 区别, difference, 最佳实践, best practice, tokio vs, async-std vs, 比较 tokio, 比较 async, Triggers on: Rust, cargo, rustc, crate, Cargo.toml, 意图分析, 问题分析, 语义分析, analyze intent, question analysis, compile error, borrow error, lifetime error, ownership error, type error, trait error, value moved, cannot borrow, does not live long enough, mismatched types, not satisfied, E0382, E0597, E0277, E0308, E0499, E0502, E0596, async, await, Send, Sync, tokio, concurrency, error handling, 编译错误, compile error, 所有权, ownership, 借用, borrow, 生命周期, lifetime, 类型错误, type error, 异步, async, 并发, concurrency, 错误处理, error handling, 问题, problem, question, 怎么用, how to use, 如何, how to, 为什么, why, 什么是, what is, 帮我写, help me write, 实现, implement, 解释, explain