agentleFS
naoyukiknaoyukik/agent-skills/skills/rust-coding-conventions/SKILL.md

rust-coding-conventions

Skill1 starsChanged 49 days agoMITView on GitHub

Mastering Rust/Win32 development by enforcing strict layered architecture (GUI -> App -> Domain <- Infra) and Win32 API isolation. This skill mandates pure Rust domains, RAII-based resource management to prevent GDI leaks, and explicit safety comments for unsafe blocks. Use during code implementation or review to ensure dependency direction and memory safety.

The file

Files
SKILL.md

Rust/Win32 コーディング規約

命名規則

対象形式例
変数・関数・モジュールsnake_casecursor_position_x
型 (Struct, Enum, Trait)PascalCaseTerminalWorkflow
定数SCREAMING_SNAKE_CASEMAX_BUFFER_SIZE
ファイル名構造体名のsnake_caseterminal_service.rs
bool型述語形式is_visible, has_focus, can_scroll

例外: Win32 API FFI境界(DllMain, OnCommand等)のみPascalCase/CamelCaseを許容。lib.rs内に限定。

アーキテクチャ

依存方向: 外側 → 内側

GUI → Application → Domain ← Infrastructure

レイヤー責務

レイヤー責務制約
Domain (src/domain/)状態、データ表現、Repository Trait定義windowsクレート依存禁止
Application (src/application/)ユースケース、レイヤー間調整具体的な描画方法を知らない
Infrastructure (src/infra/)OS/外部システムとの対話Win32 APIをここに閉じ込める
GUI (src/gui/)描画、ユーザー入力受け取り巨大関数を作らない

データモデリング

プリミティブ型の羅列を避け、意味のある構造体を定義する。

// Bad
fn handle_key(vk_code: u16, ctrl: bool, shift: bool)

// Good
fn handle_key(key: InputKey)
// where struct InputKey { code: KeyCode, modifiers: Modifiers }

安全性ガイドライン

  • unsafeの局所化: 最小限に抑える
  • Safety Comment必須: なぜunsafeが必要か、なぜ安全かを記述
  • FFI境界: 生ポインタは即座に安全なRust型に変換
  • リソース管理: DropトレイトでRAIIパターンを使用(GDIオブジェクトのリーク防止)
  • Panic禁止: unwrap()/expect()を避け、Resultを返す

ファイルサイズ

1ファイル300行制限: 超えたら設計見直しを検討

テスト戦略

レイヤー目標
Domainカバレッジ90%以上
Applicationドメインとの協調をテスト、必要に応じてモック
Infrastructure/GUIロジックを分離し、純粋な計算部分のみテスト

必須ツール

cargo fmt   # フォーマット
cargo clippy  # 警告は全て修正

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.