Rust Expert Skill
Expert in idiomatic Rust 1.75+ development with focus on CLI/system tools, ownership patterns, error handling, traits, async programming, and testing.
Core Competencies
1. Ownership & Borrowing Mastery
- Prefer
&str over String for function parameters
- Use slices (
&[T]) over Vec<T> when ownership not needed
- Leverage
Cow<str> for conditionally owned strings
- Apply
Arc<T> and Arc<Mutex<T>> for thread-safe sharing
- Design lifetimes explicitly when necessary
2. Error Handling Excellence
- Default:
anyhow::Result<T> for applications
- Libraries:
thiserror for custom error types
- Context: Always use
.context("operation description") with ?
- No unwrap: Use
? operator or expect() with justification
- Recovery: Provide actionable error messages
3. Trait-Driven Design
- Implement standard traits:
Debug, Clone, Default, Display
- Use trait objects (
dyn Trait) for runtime polymorphism
- Leverage trait bounds for generic constraints
- Organize impl blocks immediately after type definitions
- Apply async traits (native in Rust 1.75+)
4. Async Programming Patterns
- Runtime: Tokio for production async
- Patterns:
async fn, tokio::spawn, tokio::select macro (with !)
- Streams:
tokio_stream for async iteration
- Rate limiting:
governor crate for API throttling
- Retries: Exponential backoff with
tokio::time::sleep
5. CLI Development Best Practices
- Argument parsing:
clap with derive macros
- Config:
serde + toml/yaml for structured config
- Output:
indicatif for progress, colored for styling
- Terminal: Handle
SIGINT gracefully, cleanup on exit
6. Testing Strategy
- Embedded tests:
#[cfg(test)] mod tests { use super::*; }
- Unit tests alongside code, integration tests in
tests/
- Use
#[should_panic] for expected panics
- Mock external dependencies with traits
- Property-based testing with
proptest or quickcheck
7. Build Optimization
- Linker: Use
mold or lld for faster linking
- Cache:
sccache for incremental builds
- Profile:
cargo build --release with LTO
- Dependencies: Minimize with feature flags
- Workspace: Organize large projects with
workspace
8. Code Quality Standards
- Before commit:
cargo fmt, cargo clippy, cargo test
- Clippy: Zero warnings policy
- Documentation:
/// for public APIs, // with ! for modules
- Examples: Provide runnable examples in docs
9. Project Structure Patterns
- Flat module hierarchy when possible (rtk style)
src/main.rs for binaries, src/lib.rs for libraries
- Group related functionality in modules
- Keep functions focused and small
- Avoid deep nesting (max 3-4 levels)
Reference Files
This skill includes detailed patterns and checklists:
Patterns:
patterns/error-handling.md - anyhow, thiserror, Result patterns
patterns/ownership.md - &str vs String, Cow, Arc, lifetimes
patterns/async-patterns.md - Tokio, futures, async traits
patterns/traits-impl.md - Trait implementation organization
patterns/testing.md - Test organization and assertions
patterns/cli-patterns.md - clap derive, subcommands
Checklists:
checklists/code-review.md - Pre-commit review checklist
checklists/performance.md - Build optimization checklist
Anti-Patterns:
anti-patterns/common-mistakes.md - Frequent Rust mistakes
anti-patterns/memory-pitfalls.md - Ownership pitfalls
Examples:
examples/rtk-patterns.md - Real-world patterns from rtk project
When to Use This Skill
✅ Use for:
- Writing new Rust code (CLI tools, libraries, async services)
- Code review of Rust PRs
- Refactoring to idiomatic patterns
- Performance optimization
- Error handling improvements
- Test organization
❌ Don't use for:
- Simple syntax questions (use native knowledge)
- Non-Rust languages
- Project setup without coding
Integration with SuperClaude Framework
- Works with: backend-architect (system design), TDD (test-first), code-reviewer
- Flags: Responds to
--think for architectural analysis
- Mode: Compatible with
--uc token efficiency mode
- Language: English for shareability, French instructions supported
Quick Reference
Error Handling
use anyhow::{Context, Result};
fn process_file(path: &str) -> Result<()> {
let content = std::fs::read_to_string(path)
.context("Failed to read file")?;
Ok(())
}
Ownership Patterns
// Prefer borrowing
fn print_name(name: &str) { println!("{}", name); }
// Conditionally owned
use std::borrow::Cow;
fn maybe_modify(input: &str, modify: bool) -> Cow<str> {
if modify {
Cow::Owned(input.to_uppercase())
} else {
Cow::Borrowed(input)
}
}
Async Patterns
#[tokio::main]
async fn main() -> Result<()> {
let result = tokio::time::timeout(
Duration::from_secs(5),
fetch_data()
).await??;
Ok(())
}
Testing
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_calculation() {
assert_eq!(calculate(2, 3), 5);
}
}
1---2name: rust-expert3description: Expert Rust idiomatique pour développement CLI/système. Ownership, error handling avec anyhow/thiserror, traits, async Tokio, testing. Utiliser pour coder, reviewer ou refactorer du Rust.4---56# Rust Expert Skill78Expert in idiomatic Rust 1.75+ development with focus on CLI/system tools, ownership patterns, error handling, traits, async programming, and testing.910## Core Competencies1112### 1. Ownership & Borrowing Mastery13- Prefer `&str` over `String` for function parameters14- Use slices (`&[T]`) over `Vec<T>` when ownership not needed15- Leverage `Cow<str>` for conditionally owned strings16- Apply `Arc<T>` and `Arc<Mutex<T>>` for thread-safe sharing17- Design lifetimes explicitly when necessary1819### 2. Error Handling Excellence20- **Default**: `anyhow::Result<T>` for applications21- **Libraries**: `thiserror` for custom error types22- **Context**: Always use `.context("operation description")` with `?`23- **No unwrap**: Use `?` operator or `expect()` with justification24- **Recovery**: Provide actionable error messages2526### 3. Trait-Driven Design27- Implement standard traits: `Debug`, `Clone`, `Default`, `Display`28- Use trait objects (`dyn Trait`) for runtime polymorphism29- Leverage trait bounds for generic constraints30- Organize impl blocks immediately after type definitions31- Apply async traits (native in Rust 1.75+)3233### 4. Async Programming Patterns34- **Runtime**: Tokio for production async35- **Patterns**: `async fn`, `tokio::spawn`, `tokio::select` macro (with `!`)36- **Streams**: `tokio_stream` for async iteration37- **Rate limiting**: `governor` crate for API throttling38- **Retries**: Exponential backoff with `tokio::time::sleep`3940### 5. CLI Development Best Practices41- **Argument parsing**: `clap` with derive macros42- **Config**: `serde` + `toml`/`yaml` for structured config43- **Output**: `indicatif` for progress, `colored` for styling44- **Terminal**: Handle `SIGINT` gracefully, cleanup on exit4546### 6. Testing Strategy47- Embedded tests: `#[cfg(test)] mod tests { use super::*; }`48- Unit tests alongside code, integration tests in `tests/`49- Use `#[should_panic]` for expected panics50- Mock external dependencies with traits51- Property-based testing with `proptest` or `quickcheck`5253### 7. Build Optimization54- **Linker**: Use `mold` or `lld` for faster linking55- **Cache**: `sccache` for incremental builds56- **Profile**: `cargo build --release` with LTO57- **Dependencies**: Minimize with feature flags58- **Workspace**: Organize large projects with `workspace`5960### 8. Code Quality Standards61- **Before commit**: `cargo fmt`, `cargo clippy`, `cargo test`62- **Clippy**: Zero warnings policy63- **Documentation**: `///` for public APIs, `//` with `!` for modules64- **Examples**: Provide runnable examples in docs6566### 9. Project Structure Patterns67- Flat module hierarchy when possible (rtk style)68- `src/main.rs` for binaries, `src/lib.rs` for libraries69- Group related functionality in modules70- Keep functions focused and small71- Avoid deep nesting (max 3-4 levels)7273## Reference Files7475This skill includes detailed patterns and checklists:7677- **Patterns**:78 - `patterns/error-handling.md` - anyhow, thiserror, Result patterns79 - `patterns/ownership.md` - &str vs String, Cow, Arc, lifetimes80 - `patterns/async-patterns.md` - Tokio, futures, async traits81 - `patterns/traits-impl.md` - Trait implementation organization82 - `patterns/testing.md` - Test organization and assertions83 - `patterns/cli-patterns.md` - clap derive, subcommands8485- **Checklists**:86 - `checklists/code-review.md` - Pre-commit review checklist87 - `checklists/performance.md` - Build optimization checklist8889- **Anti-Patterns**:90 - `anti-patterns/common-mistakes.md` - Frequent Rust mistakes91 - `anti-patterns/memory-pitfalls.md` - Ownership pitfalls9293- **Examples**:94 - `examples/rtk-patterns.md` - Real-world patterns from rtk project9596## When to Use This Skill9798✅ **Use for**:99- Writing new Rust code (CLI tools, libraries, async services)100- Code review of Rust PRs101- Refactoring to idiomatic patterns102- Performance optimization103- Error handling improvements104- Test organization105106❌ **Don't use for**:107- Simple syntax questions (use native knowledge)108- Non-Rust languages109- Project setup without coding110111## Integration with SuperClaude Framework112113- **Works with**: backend-architect (system design), TDD (test-first), code-reviewer114- **Flags**: Responds to `--think` for architectural analysis115- **Mode**: Compatible with `--uc` token efficiency mode116- **Language**: English for shareability, French instructions supported117118## Quick Reference119120### Error Handling121```rust122use anyhow::{Context, Result};123124fn process_file(path: &str) -> Result<()> {125 let content = std::fs::read_to_string(path)126 .context("Failed to read file")?;127 Ok(())128}129```130131### Ownership Patterns132```rust133// Prefer borrowing134fn print_name(name: &str) { println!("{}", name); }135136// Conditionally owned137use std::borrow::Cow;138fn maybe_modify(input: &str, modify: bool) -> Cow<str> {139 if modify {140 Cow::Owned(input.to_uppercase())141 } else {142 Cow::Borrowed(input)143 }144}145```146147### Async Patterns148```rust149#[tokio::main]150async fn main() -> Result<()> {151 let result = tokio::time::timeout(152 Duration::from_secs(5),153 fetch_data()154 ).await??;155 Ok(())156}157```158159### Testing160```rust161#[cfg(test)]162mod tests {163 use super::*;164165 #[test]166 fn test_calculation() {167 assert_eq!(calculate(2, 3), 5);168 }169}170```