Back to Skills

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.

2,202stars169forksUpdated 1/23/2026

Security Assessment

Safe(100/100)
Security Score100/100

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.

All Files

4 files
helpers.md6.2 KB
View
SKILL.md2.0 KB
View
gotchas.md8.7 KB
View
patterns.md9.8 KB
View

Install async-drop

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill

Repository

cryfs/cryfs