本文へスキップ
Skillpedia
一般的なプログラミング41k · #6800

rust-async-patterns

できること

このスキルは、Rustで非同期コード(async)を使ったプログラミングを支援します。Tokioなどのツールを使い、プログラムを止めることなく複数の処理を同時に進める方法を教えます。

使う場面

  • ✓複数の処理を同時に行う必要があるRustプログラムを作っているとき。
  • ✓多くの接続を扱うネットワークシステムを作るとき。
  • ✓非同期のRustコードのデバッグや性能の最適化を行うとき。

スキルのリンク

https://github.com/wshobson/agents/blob/main/plugins/systems-programming/skills/rust-async-patterns/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/wshobson/agents/blob/main/plugins/systems-programming/skills/rust-async-patterns/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“Rustプログラムで2つの処理を同時に待ち、先に終わった方の結果を受け取るにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

このツールは、Rustで非同期コードがどのように動くかという基本的な考え方を説明します。「タスク」が並行して実行される仕組みや、後から完了する計算である「future」の使い方を示します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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::sleep in 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
よくある質問

Rustにおける「async」とは何ですか?

インターネットからの応答のように時間のかかる処理を待っている間も、プログラム全体を止めずに他の処理を進められるように書く方法です。

Tokioとは何ですか?

Rustで非同期コードを効率よく管理・実行するための、人気のあるツールです。

非同期Rustにおける「タスク」とは何ですか?

他のコードと独立して、同時に実行できる非同期コードのまとまりのことです。

詳細

作者による元の説明

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.

repo: wshobson/agents

人気

GitHubのスター
41k
ランキング
#6800
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル