rust-best-practices
This skill provides structured guidance for Rust development based on Microsoft's Pragmatic Rust Guidelines. It covers error handling patterns (thiserror for libraries, anyhow for applications), API design principles including builder patterns and newtypes, ownership and type system practices, and idiomatic Rust patterns for performance and maintainability. Use it when writing, reviewing, or modifying Rust code to ensure adherence to community standards and best practices.
git clone --depth 1 https://github.com/majiayu000/spellbook /tmp/rust-best-practices && cp -r /tmp/rust-best-practices/plugins/rust-dev/skills/rust-best-practices. ~/.claude/skills/rust-best-practicesrust-best-practices.SKILL.md
# Rust Best Practices Assistant ## Core Principles - Prefer safe Rust; use `unsafe` only when absolutely necessary and well-documented - Leverage the type system to prevent bugs at compile time - Use `Result<T, E>` for error handling, avoid `panic!` in library code - Make illegal states unrepresentable through proper type design ## Code Style - Format all code with `rustfmt` - Follow all `clippy` suggestions (run with `cargo clippy -- -W clippy::pedantic`) - Use `snake_case` for variables and functions - Use `CamelCase` for types and traits - Use `SCREAMING_SNAKE_CASE` for constants ## Memory & Ownership - Prefer borrowing (`&T`, `&mut T`) over ownership when possible - Use `Cow<str>` for strings that might be borrowed or owned - Avoid unnecessary `.clone()` - consider borrowing or restructuring - Use `Arc<T>` for shared ownership across threads, `Rc<T>` for single-threaded ## Error Handling - Use `thiserror` for defining library error types - Use `anyhow` for application-level error handling - Provide meaningful, actionable error messages - Use `?` operator for error propagation ## Performance - Avoid unnecessary heap allocations - Prefer iterators over manual loops (zero-cost abstraction) - Use `&str` instead of `String` for function parameters when possible - Consider using `SmallVec` for small, stack-allocated vectors ## Async Rust - Use `tokio` as the async runtime for most applications - Prefer `async fn` over manual `Future` implementations - Avoid blocking operations in async contexts - Use `tokio::spawn` for concurrent tasks ## Testing - Write unit tests in the same file using `#[cfg(test)]` module - Use `#[should_panic]` for testing panic behavior - Use `proptest` or `quickcheck` for property-based testing - Aim for meaningful test coverage, not just line coverage ## Common Patterns - Use the builder pattern for complex object construction - Use `From` and `Into` traits for type conversions - Implement `Default` when a sensible default exists - Use `Option<T>` instead of sentinel values ## What to Avoid - Avoid `unwrap()` in production code; use `expect()` with context or proper error handling - Avoid `String` when `&str` suffices - Avoid manual memory management when safe abstractions exist - Avoid `unsafe` without thorough documentation and testing
Audit AND optimize a CLAUDE.md / AGENTS.md instruction file — score it against the five high-leverage patterns, flag anti-patterns, then apply approved fixes in place. Use when the user says 优化 CLAUDE.md / 优化 AGENTS.md / optimize my agent doc / 帮我改 claudemd, or after an audit when they want the fixes applied (not just reported).
Generate or update repository-specific AGENTS.md instruction files from real repo evidence. Use when asked to create, design, scaffold, split, or improve root or scoped AGENTS.md files for Codex/Claude/agent workflows, especially when a repo needs directory-specific rules, validation commands, generated-file boundaries, or a short agent onboarding router.
REST/GraphQL/gRPC API design best practices. Use when designing APIs, defining contracts, handling versioning. Covers OpenAPI 3.2, GraphQL Federation, gRPC streaming.
Mobile app UI design expert for iOS and Android. Use when designing app interfaces, creating design systems, ensuring accessibility, or following platform guidelines. Covers Material Design 3, Human Interface Guidelines, color theory, typography, and 2025 trends.
End-to-end app feature inventory and user-story testing workflow with a canonical tracker. Use when the user asks to audit every feature, derive expected behavior from code, test user journeys, or explicitly fix and retest documented UX or logistical defects.
Design architecture foundations before implementation. Use when asked to design or refactor architecture, choose Rust/Go crate, package, module, runtime, workflow, or service boundaries, compare mature project architecture, prevent stacked one-off PRs, audit migration debt in existing repos, or produce a spec before coding.
Evidence-driven architecture research for understanding real systems and making technical decisions. Use when doing architecture landscape studies, source-backed system archaeology, build-vs-buy or adopt/adapt/build decisions, open-source and commercial comparisons, revisiting an earlier architecture choice, or handling requests such as 架构调研, 架构选型, 竞品架构, 技术尽调, 同类方案, 开源替代, how is X built, and what should we learn from X. Do not use for small mechanical changes, market-only discovery, or detailed design after the technology direction is already fixed.
Ask Grok or Gemini via opencli (browser-session based, no API cost). Use when the user says "问 grok", "问 gemini", "ask grok", "ask gemini", "用 grok 查", "grok 怎么看", "让 gemini 分析", or wants a second opinion from Grok/Gemini without paying API tokens. Routes to opencli which drives the already-logged-in Chrome session.