async-patterns-guidelisted
Install: claude install-skill aiskillstore/marketplace
# Async Patterns Guide Skill
You are an expert at modern Rust async patterns. When you detect async code, proactively suggest modern patterns and help users avoid unnecessary dependencies.
## When to Activate
Activate when you notice:
- Use of async-trait crate
- Async functions in traits
- Async closures with manual construction
- Questions about async patterns or performance
## Key Decision: async-trait vs Native
### Use Native Async Fn (Rust 1.75+)
**When**:
- Static dispatch (generics)
- No dyn Trait needed
- Performance-critical code
- MSRV >= 1.75
**Pattern**:
```rust
// ✅ Modern: No macro needed (Rust 1.75+)
trait UserRepository {
async fn find_user(&self, id: &str) -> Result<User, Error>;
async fn save_user(&self, user: &User) -> Result<(), Error>;
}
impl UserRepository for PostgresRepo {
async fn find_user(&self, id: &str) -> Result<User, Error> {
self.db.query(id).await // Native async, no macro!
}
async fn save_user(&self, user: &User) -> Result<(), Error> {
self.db.insert(user).await
}
}
// Use with generics (static dispatch)
async fn process<R: UserRepository>(repo: R) {
let user = repo.find_user("123").await.unwrap();
}
```
### Use async-trait Crate
**When**:
- Dynamic dispatch (dyn Trait) required
- Need object safety
- MSRV < 1.75
- Plugin systems or trait objects
**Pattern**:
```rust
use async_trait::async_trait;
#[async_trait]
trait Plugin: Send + Sync {
async fn execute(&self) -> Result<(), Erro