plugins/rust-expert/skills/rust-async-concurrency/SKILL.md
Use when writing async Rust — spawning tasks, sharing state across tasks/threads, choosing channels vs mutexes, or hitting Send-bound errors with async traits. Covers tokio runtime, Mutex/RwLock/atomics, mpsc/oneshot/broadcast/watch, spawn_blocking, and the async-fn-in-traits Send problem. Do NOT use for HTTP service structure — routing, extractors, middleware (use rust-web-backend) — or sync-only ownership questions (use rust-core-language).
npx skillsauth add fusengine/agents rust-async-concurrencyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Before writing async code, spawn in parallel:
After writing, run fuse-ai-pilot:sniper.
| Runtime | Reality | |---------|---------| | tokio | The de-facto standard. Almost every async crate (axum, sqlx, reqwest, tonic) targets it. Default choice. | | async-std | Niche, effectively in maintenance mode. Do not pick for new work. | | smol | Niche, small/embeddable. Only for constrained or embedded contexts. |
Default to tokio unless a hard constraint says otherwise.
std::sync::Mutex first — it is faster. Reach for tokio::sync::Mutex ONLY when the guard must be held across an .await. Otherwise scope the guard so its destructor runs before the await.Arc<Mutex<T>> is not the default — analyze contention first. Read-dominated → RwLock; a simple counter → atomics; work that is itself async → a task + message passing.JoinHandle you care about — a dropped tokio::spawn handle silently swallows the task's panic/error. .await it, or use JoinSet/tracing to surface failures.spawn_blocking for heavy sync work — CPU-bound loops or blocking I/O (std file, blocking DB driver) starve the runtime if run on an async worker. Offload them.Send across .await — everything held across an await point must be Send for tokio::spawn. A std::sync::MutexGuard is NOT Send; holding one across an await is a compile error (and async-mutex guards that are Send deadlock instead).| Topic | Reference | When to Consult |
|-------|-----------|-----------------|
| Runtime & tasks | runtime-and-tasks.md | spawn, JoinHandle, JoinSet, spawn_blocking, 'static bound |
| Shared state | shared-state.md | Choosing Mutex vs RwLock vs atomics vs actor task |
| Channels | channels.md | Picking mpsc / oneshot / broadcast / watch |
| Async traits | async-traits.md | async fn in traits + the Send-bound problem |
| Template | When to Use | |----------|-------------| | task-patterns.md | Concurrent tasks, JoinSet, actor pattern, spawn_blocking | | graceful-shutdown.md | Cancellation, shutdown signal, draining tasks |
.await// GOOD: lock released before the await
{
let mut db = state.lock().unwrap();
db.insert(key, value);
} // guard dropped here
do_async_work().await;
→ See shared-state.md
// one value back to a caller → oneshot
// many producers, one consumer → mpsc
// fan-out same value to all → broadcast
// latest-value-only state → watch
→ See channels.md
.await handles, or collect them with JoinSet.spawn_blocking.tokio::sync::Mutex by reflex — it wraps a sync mutex internally and rarely helps throughput.tokio::spawn whose result or panic matters.async fn in traits gives you Send futures — it does not (see async-traits.md).testing
Copy self-audit and ban-lists — filler verbs/hype adjectives, slop placeholder names, fake-precise numbers, Title Case headlines, humor in error copy ('Oops!'), em-dash crutch, one copy register per page.
development
Logged-in web apps — dashboards, auth flows, settings, onboarding, data tables, command palettes, modals, toasts. Register `product`: density and glance-speed over marketing polish, no hero/CTA-tricks, every data surface covers empty/loading/error explicitly, tables and dataviz follow preattentive-processing rules.
development
Marketing sites, landing pages, campaign pages — register `brand` (design IS the product). Structure comes from the register's POV + a macrostructure pick, never from copying an inspiration site's section flow. Hero discipline, deviated section order, asymmetric grids, and a silhouette lookalike-test gate before ship.
development
Token-strategy core — OKLCH color rules, neutral tinting, accent-commitment levels, type scale, 8pt spacing grid, touch targets, and the canonical output format of design-system.md (the file the harness gates on). This is routing step 1 of design-method/SKILL.md — read it before design-web/design-webapp/design-ios/design-android, before picking or auditing a single color/type/spacing value.