async-drop
Guide to the AsyncDrop pattern for async cleanup in Rust. Use when working with AsyncDropGuard, implementing AsyncDrop trait, or handling async resource cleanup.
Security Assessment
About async-drop
The AsyncDrop skill provides a pattern in Rust for handling asynchronous cleanup of resources. In Rust, the `Drop` trait is synchronous, but many resources like network connections, file handles, and background tasks require asynchronous teardown. The AsyncDrop pattern solves this issue by enabling the use of asynchronous cleanup within the Rust ecosystem. It provides a way to ensure that cleanup happens correctly and in a timely manner, even in asynchronous contexts, by utilizing the `AsyncDropGuard` type and the `AsyncDrop` trait.
FAQ
What is the purpose of the AsyncDrop pattern?
The AsyncDrop pattern solves the problem of performing asynchronous cleanup in Rust, where the `Drop` trait is synchronous but cleanup often needs to be done asynchronously.
How do I use the `AsyncDropGuard`?
To use the `AsyncDropGuard`, create a new instance by wrapping the resource in `AsyncDropGuard::new()`. You must then explicitly call `async_drop().await` before the guard goes out of scope to ensure proper cleanup.
Are there any requirements for using AsyncDrop?
Yes, you must always call `async_drop()` on every `AsyncDropGuard` to trigger the cleanup process. Additionally, types containing guards should implement the `AsyncDrop` trait for proper resource management.
Can I skip calling `async_drop()` on panic paths?
Yes, it is acceptable to skip calling `async_drop()` during panic paths, as the cleanup process can be deferred during such situations.
What happens if I forget to call `async_drop()`?
Forgetting to call `async_drop()` will cause a panic, alerting you to the missing cleanup operation and preventing resource leaks.
Install async-drop
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
cryfs/cryfs