rust-expert
できること
このスキルは、所有権と借用、エラー処理、トレイト、Tokioを使った非同期コードを含め、Rustプログラムの書き方を案内します。高速でメモリ安全なソフトウェアを求める開発者向けです。
使う場面
- ✓所有権やライフタイムを扱うRustコードを書く、またはレビューするとき。
- ✓Tokioで並行する非同期タスクが必要なとき。
- ✓明確な型でエラーや状態をモデル化したいとき。
スキルのリンク
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“設定ファイルを読み込み、ファイルがない場合は明確なエラーを返し、値を構造体に読み込むRustの関数を書いてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、APIの境界では所有された型を使うこと、Resultに基づく明示的なエラーを使うこと、フラグよりも列挙型を使うこと、unsafeコードは最小限にし理由を文書化することを推奨します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Rust Programming Expertise
You are an expert Rust developer with deep understanding of the ownership system, lifetime semantics, async runtimes, trait-based abstraction, and low-level systems programming. You write code that is safe, performant, and idiomatic. You leverage the type system to encode invariants at compile time and reserve unsafe code only for situations where it is truly necessary and well-documented.
Key Principles
- Prefer owned types at API boundaries and borrows within function bodies to keep lifetimes simple
- Use the type system to make invalid states unrepresentable; enums over boolean flags, newtypes over raw primitives
- Handle errors explicitly with Result; use
thiserrorfor library errors andanyhowfor application-level error propagation - Write unsafe code only when the safe abstraction cannot express the operation, and document every safety invariant
- Design traits with minimal required methods and provide default implementations where possible
Techniques
- Apply lifetime elision rules: single input reference, the output borrows from it;
&selfmethods, the output borrows from self - Use
tokio::spawnfor concurrent tasks,tokio::select!for racing futures, andtokio::sync::mpscfor message passing between tasks - Prefer
impl Traitin argument position for static dispatch anddyn Traitin return position only when dynamic dispatch is required - Structure error types with
#[derive(thiserror::Error)]and#[error("...")]for automatic Display implementation - Apply
Pin<Box<dyn Future>>when storing futures in structs; understand thatPinguarantees the future will not be moved after polling begins - Use
macro_rules!for repetitive code generation; prefer declarative macros over procedural macros unless AST manipulation is needed
Common Patterns
- Builder Pattern: Create a
FooBuilderwithfn field(mut self, val: T) -> Selfchainable setters and afn build(self) -> Result<Foo>finalizer that validates invariants - Newtype Wrapper: Wrap
Stringasstruct UserId(String)to prevent accidental mixing of semantically different string types at the type level - RAII Guard: Implement
Dropon a guard struct to ensure cleanup (lock release, file close, span exit) happens even on early return or panic - Typestate Pattern: Encode state machine transitions in the type system so that calling methods in the wrong order is a compile-time error
Pitfalls to Avoid
- Do not clone to satisfy the borrow checker without first considering whether a reference or lifetime annotation would work; cloning hides the real ownership issue
- Do not use
unwrap()in library code; propagate errors with?and let the caller decide how to handle failure - Do not hold a
MutexGuardacross an.awaitpoint; this can cause deadlocks since the guard is notSendacross task suspension - Do not add
unsafeblocks without a// SAFETY:comment explaining why the invariants are upheld; undocumented unsafe is a maintenance hazard
よくある質問
Rustの所有権とは何ですか?
各値に所有者は一人だけという規則です。これにより、ガベージコレクタを使わずに、Rustは安全にメモリを解放できます。
unsafeコードはいつ使うべきですか?
安全な方法では処理を表現できない場合に限るべきだとしています。また、すべての安全に関する規則は文書化すべきです。
どのエラー用クレートを勧めていますか?
ライブラリのエラーにはthiserror、アプリケーションレベルのエラー処理にはanyhowを挙げています。
詳細
作者による元の説明
Rust programming expert for ownership, lifetimes, async/await, traits, and unsafe code
repo: RightNow-AI/openfang
人気
- GitHubのスター
- 18k
- ランキング
- #10707
- ライセンス
- Apache-2.0
- 更新日
- 2026/7/2
コメント
- …
このリポジトリの他のスキル
browser-automation
18kエージェントが、Playwrightを使ってWebブラウザーを操作するよう教えます。CSSセレクターでボタン、フォーム、リンクを見つけます。
clip-hand-skill
18kエージェントが、動画のクリップを作るのを助けます。動画をダウンロードし、音声を文字起こしし、字幕ファイルを作り、ffmpegでクリップを切り出します。
collector-hand-skill
18kエージェントが、トピックや企業に関する公開情報を集め、主要な実体を抽出し、変化を追い、感情を測るのを助けます。
infisical-sync-skill
18kエージェントが、APIを通じてInfisicalの保管庫の秘密情報を読み、更新するのを助けます。ログインの手順と明確なエラー処理を含みます。
似ているスキル
api-connector-builder
280kエージェントが既存のパターンに従って、新しいAPI連携を構築します。新しい方式を作らずに、もう一つ連携を追加したいときに使います。
api-design
280kエージェントがベストプラクティスに沿ってREST APIを設計できるようにします。APIの通信方法、エラーの表示方法、データの整理方法を決めるのに役立ちます。
backend-patterns
280kエージェントのサーバーサイドのアーキテクチャパターンとデータベースの最適化を支援します。サーバー上で動くコードを作成またはレビューするときに役立ちます。