Master Rust async programming with Tokio, async traits
Rust async patterns

Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns. Use when building async Rust applications, implementing concurrent systems, or debugging async code.
--- name: rust-async-patterns description: Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns. Use when building async Rust applications, implementing concurrent systems, or debugging async code. --- # Rust Async Patterns Production patterns for async Rust programming with Tokio runtime, including tasks, channels, streams, and error handling. ## When to Use This Skill - Building async Rust applications - Implementing concurrent network services - Using Tokio for async I/O - Handling async errors properly - Debugging async code issues - Optimizing async performance
Overview
Production patterns for async Rust programming with Tokio runtime, including tasks, channels, streams, and error handling.
Manual install (npx, ZIP)
Claude Code
npx skills add wshobson/agents --skill rust-async-patterns -g -a claude-codeClaude Code (manual)
mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \
| tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/systems-programming/skills/rust-async-patternsWindows (PowerShell)
New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/e8017f5ed5fe4554e65b/rust-async-patterns.zip" -OutFile "$env:TEMP\rust-async-patterns.zip"; Expand-Archive "$env:TEMP\rust-async-patterns.zip" -DestinationPath "$HOME\.claude\skills" -ForceClaude.ai / desktop
Codex, Cursor, other agents
Connects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md2.6 KBreferences/1 file · 9.7 KB
Read the files here
SKILL.md
Show the full text96 lines
Rust Async Patterns
Production patterns for async Rust programming with Tokio runtime, including tasks, channels, streams, and error handling.
When to Use This Skill
- Building async Rust applications
- Implementing concurrent network services
- Using Tokio for async I/O
- Handling async errors properly
- Debugging async code issues
- Optimizing async performance
Core Concepts
1. Async Execution Model
Future (lazy) → poll() → Ready(value) | Pending
↑ ↓
Waker ← Runtime schedules
2. Key Abstractions
| Concept | Purpose |
|---|---|
Future |
Lazy computation that may complete later |
async fn |
Function returning impl Future |
await |
Suspend until future completes |
Task |
Spawned future running concurrently |
Runtime |
Executor that polls futures |
Quick Start
# Cargo.toml
[dependencies]
tokio = { version = "1", features = ["full"] }
futures = "0.3"
async-trait = "0.1"
anyhow = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
use tokio::time::{sleep, Duration};
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize tracing
tracing_subscriber::fmt::init();
// Async operations
let result = fetch_data("https://api.example.com").await?;
println!("Got: {}", result);
Ok(())
}
async fn fetch_data(url: &str) -> Result<String> {
// Simulated async operation
sleep(Duration::from_millis(100)).await;
Ok(format!("Data from {}", url))
}
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
Do's
- Use
tokio::select!- For racing futures - Prefer channels - Over shared state when possible
- Use
JoinSet- For managing multiple tasks - Instrument with tracing - For debugging async code
- Handle cancellation - Check
CancellationToken
Don'ts
- Don't block - Never use
std::thread::sleepin async - Don't hold locks across awaits - Causes deadlocks
- Don't spawn unboundedly - Use semaphores for limits
- Don't ignore errors - Propagate with
?or log - Don't forget Send bounds - For spawned futures
| 1 | |
| 2 | name rust-async-patterns |
| 3 | description Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns. Use when building async Rust applications, implementing concurrent systems, or debugging async code. |
| 4 | |
| 5 | |
| 6 | # Rust Async Patterns |
| 7 | |
| 8 | Production patterns for async Rust programming with Tokio runtime, including tasks, channels, streams, and error handling. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | Building async Rust applications |
| 13 | Implementing concurrent network services |
| 14 | Using Tokio for async I/O |
| 15 | Handling async errors properly |
| 16 | Debugging async code issues |
| 17 | Optimizing async performance |
| 18 | |
| 19 | ## Core Concepts |
| 20 | |
| 21 | ### 1. Async Execution Model |
| 22 | |
| 23 | |
| 24 | Future (lazy) → poll() → Ready(value) | Pending |
| 25 | ↑ ↓ |
| 26 | Waker ← Runtime schedules |
| 27 | |
| 28 | |
| 29 | ### 2. Key Abstractions |
| 30 | |
| 31 | | Concept | Purpose | |
| 32 | | ---------- | ---------------------------------------- | |
| 33 | | `Future` | Lazy computation that may complete later | |
| 34 | | `async fn` | Function returning impl Future | |
| 35 | | `await` | Suspend until future completes | |
| 36 | | `Task` | Spawned future running concurrently | |
| 37 | | `Runtime` | Executor that polls futures | |
| 38 | |
| 39 | ## Quick Start |
| 40 | |
| 41 | |
| 42 | # Cargo.toml |
| 43 | [dependencies] |
| 44 | tokio = { version = "1", features = ["full"] } |
| 45 | futures = "0.3" |
| 46 | async-trait = "0.1" |
| 47 | anyhow = "1.0" |
| 48 | tracing = "0.1" |
| 49 | tracing-subscriber = "0.3" |
| 50 | |
| 51 | |
| 52 | |
| 53 | use tokio::time::{sleep, Duration}; |
| 54 | use anyhow::Result; |
| 55 | |
| 56 | #[tokio::main] |
| 57 | async fn main() -> Result<()> { |
| 58 | // Initialize tracing |
| 59 | tracing_subscriber::fmt::init(); |
| 60 | |
| 61 | // Async operations |
| 62 | let result = fetch_data("https://api.example.com").await?; |
| 63 | println!("Got: {}", result); |
| 64 | |
| 65 | Ok(()) |
| 66 | } |
| 67 | |
| 68 | async fn fetch_data(url: &str) -> Result<String> { |
| 69 | // Simulated async operation |
| 70 | sleep(Duration::from_millis(100)).await; |
| 71 | Ok(format!("Data from {}", url)) |
| 72 | } |
| 73 | |
| 74 | |
| 75 | ## Detailed patterns and worked examples |
| 76 | |
| 77 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 78 | |
| 79 | ## Best Practices |
| 80 | |
| 81 | ### Do's |
| 82 | |
| 83 | **Use `tokio::select!`** - For racing futures |
| 84 | **Prefer channels** - Over shared state when possible |
| 85 | **Use `JoinSet`** - For managing multiple tasks |
| 86 | **Instrument with tracing** - For debugging async code |
| 87 | **Handle cancellation** - Check `CancellationToken` |
| 88 | |
| 89 | ### Don'ts |
| 90 | |
| 91 | **Don't block** - Never use `std::thread::sleep` in async |
| 92 | **Don't hold locks across awaits** - Causes deadlocks |
| 93 | **Don't spawn unboundedly** - Use semaphores for limits |
| 94 | **Don't ignore errors** - Propagate with `?` or log |
| 95 | **Don't forget Send bounds** - For spawned futures |
| 96 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
SkillA task is too large for one model passAdvisor orchestrator worker
SkillRun the CCS Align seat's hourly breathing cycleCCS Align — Worker Watch seat (Phases 0–2 shipped; Phase 3 = verify / sign-off)
SkillSummarize and review what changed while you were awayCatchup — Async-Team Return Briefing
SkillMaster Python asyncio, concurrent programmingAsync python patterns
SkillMaster Go concurrency with goroutines, channelsGo concurrency patterns
SkillDesign microservices architectures with service boundariesMicroservices patternsMore from wshobson
SkillMaster C/.NET backend development patterns for building
SkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliance
SkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Design
SkillMigrate from AngularJS to Angular using hybrid modeAngular migration
SkillUnderstand anti-reversing, obfuscationAnti reversing techniques
SkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patterns