技能 rust-async-patterns

rust-async-patterns

安全 🌐 網路存取⚙️ 外部命令

快速學習非同步 Rust 模式

非同步 Rust 可能很難結構化和除錯。這個技能提供清晰的 Tokio 任務、通道、流和錯誤模式。

支援: Claude Codex Code(CC)
📊 69 充足
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「rust-async-patterns」。 Explain how to limit concurrency for async HTTP requests in Tokio.

預期結果:

  • Use a stream over URLs and apply buffer_unordered with a limit
  • Collect results and handle errors per request
  • Avoid unbounded spawning to protect memory and sockets

正在使用「rust-async-patterns」。 Show me how to coordinate between async tasks using channels.

預期結果:

  • Use mpsc::channel for one-to-one communication between producer and consumer
  • Use broadcast::channel when multiple consumers need the same message
  • Use oneshot::channel when you need a single response from a spawned task

正在使用「rust-async-patterns」。 How do I handle errors in async Rust code properly?

預期結果:

  • Use anyhow for application-level errors with context chaining
  • Use thiserror for library code to create custom error types
  • Wrap operations with timeout to prevent indefinite hanging

安全審計

安全
v4 • 1/17/2026

Pure educational documentation containing Rust async programming examples. All static findings are false positives: 'process spawn' refers to tokio::spawn for async task management (not command execution), 'backtick execution' refers to markdown code formatting, and 'weak cryptographic algorithm' refers to keywords in documentation fields. The skill contains no tool definitions, file access, network calls, or command execution capabilities.

2
已掃描檔案
694
分析行數
2
發現項
4
審計總數
審計者: claude 查看審計歷史 →

品質評分

38
架構
100
可維護性
85
內容
22
社群
100
安全
87
規範符合性

你能建構什麼

建構並發服務

在非同步 Rust 服務中應用結構化模式來進行任務編排、錯誤處理和關機。

除錯非同步死結

使用追蹤指南和常見陷阱來診斷卡住的任務和鎖的不當使用。

學習非同步概念

透過簡短且聚焦的範例學習 future、await、流和通道。

試試這些提示

非同步快速入門
提供一個簡短的 Tokio 非同步 main 範例,包含追蹤和模擬的非同步呼叫。每個步驟用一句話說明。
並發限制
展示一個使用 Tokio 或 future 流來限制 URL 清單中並發非同步任務數量的模式。
優雅關機
說明使用 CancellationToken 和關機廣播通道來實現優雅關機的方法。
非同步特徵設計
提供一個儲存庫的非同步特徵設計,包含 get、save 和 delete 方法,並說明特徵物件的使用方式。

最佳實務

  • 使用 tokio::select! 來安全地競爭 futures
  • 優先使用通道進行協調,而非共享的可變狀態
  • 為非同步任務加入追蹤以提高可觀測性

避免

  • 在非同步程式碼中呼叫阻塞函數如 std::thread::sleep
  • 在 await 點之間持有 mutex 或 rwlock 守護
  • 產生無限數量的任務而沒有並發限制

常見問題

這與目前的 Tokio 版本相容嗎?
是的,這些模式針對 Tokio 1.x 和標準的 Rust 非同步語法。
它會產生完整的應用程式碼嗎?
不,它提供聚焦的模式和範例,而非完整的專案。
我可以在現有的儲存庫中使用它嗎?
是的,將這些模式應用到您目前的非同步模組和服務中。
它會存取或儲存我的資料嗎?
不,它是靜態指導,不會讀取檔案或傳送資料。
如果我的非同步程式碼仍然卡住怎麼辦?
使用追蹤、檢查鎖定的 await,並加入取消路徑。
這與一般的非同步指南有何不同?
它專注於實用的 Tokio 模式、任務、通道和關機流程。

開發者詳情

檔案結構

📄 SKILL.md