| created | "2025-12-16T00:00:00.000Z" |
| modified | "2026-05-09T00:00:00.000Z" |
| reviewed | "2026-04-25T00:00:00.000Z" |
| name | rust-development |
| description | Rust development โ cargo, clippy, rustfmt, async, Tokio, Serde, memory safety. Use when mentioning Rust, cargo, ownership, lifetimes, fearless concurrency, or async programming. |
| user-invocable | false |
| allowed-tools | Glob, Grep, Read, Bash, Edit, Write, TodoWrite, WebFetch, WebSearch, BashOutput, KillShell |
Rust Development
Expert knowledge for modern systems programming with Rust, focusing on memory safety, fearless concurrency, and zero-cost abstractions.
When to Use This Skill
| Use this skill when... | Use sibling skill instead when... |
|---|
| Writing Rust code, ownership, lifetimes, async/await | Configuring lint rules in detail -- use clippy-advanced |
| Choosing crates from the ecosystem (Tokio, Serde) | Detecting unused dependencies -- use cargo-machete |
| Designing module structure or trait hierarchies | Running tests with parallel isolation -- use cargo-nextest |
| Learning idiomatic Rust patterns and edition features | Generating coverage reports -- use cargo-llvm-cov |
Core Expertise
Modern Rust Ecosystem
- Cargo: Build system, package manager, and workspace management
- Rustc: Compiler optimization, target management, and cross-compilation
- Clippy: Linting for idiomatic code and performance improvements
- Rustfmt: Consistent code formatting following Rust style guidelines
- Rust-analyzer: Advanced IDE support with LSP integration
Language Features
- Rust 2024 edition: RPITIT, async fn in traits, impl Trait improvements
- Const generics and compile-time computation
- Generic associated types (GATs)
- Let-else patterns and if-let chains
Key Capabilities
Ownership & Memory Safety
- Implement ownership patterns with borrowing and lifetimes
- Design zero-copy abstractions and efficient memory layouts
- Apply RAII patterns through Drop trait and smart pointers (Box, Rc, Arc)
- Leverage interior mutability patterns (Cell, RefCell, Mutex, RwLock)
- Use Pin/Unpin for self-referential structures
Async Programming & Concurrency
- Tokio: Async runtime for high-performance network applications
- async-std: Alternative async runtime with familiar API design
- Futures: Composable async abstractions and stream processing
- Rayon: Data parallelism with work-stealing thread pools
- Design lock-free data structures with atomics and memory ordering
Error Handling & Type Safety
- Design comprehensive error types with thiserror and anyhow
- Implement Result<T, E> and Option patterns effectively
- Use pattern matching for exhaustive error handling
- Apply type-state patterns for compile-time guarantees
Performance Optimization
- Profile with cargo-flamegraph, perf, and criterion benchmarks
- Optimize with SIMD intrinsics and auto-vectorization
- Implement zero-cost abstractions and inline optimizations
- Use unsafe code judiciously with proper safety documentation
Testing & Quality Assurance
- Unit Testing: #[test] modules with assertions
- Integration Testing: tests/ directory for end-to-end validation
- Criterion: Micro-benchmarking with statistical analysis
- Miri: Undefined behavior detection in unsafe code
- Fuzzing: cargo-fuzz for security and robustness testing
Essential Commands
cargo new my-project
cargo new my-lib --lib
cargo init
cargo generate --git <template-url> --name my-project
cargo build
cargo build --release
cargo run
cargo run --release
cargo test
cargo test --lib
cargo bench
cargo clippy
cargo clippy -- -W clippy::pedantic
cargo fmt
cargo fmt --check
cargo fix
cargo add serde --features derive
cargo update
cargo audit
cargo deny check
cargo expand
cargo flamegraph
cargo doc --open
cargo miri test
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown
Best Practices
Idiomatic Rust Patterns
let sum: i32 = numbers.iter().filter(|x| **x > 0).sum();
let value = config.get("key")
.and_then(|v| v.parse().ok())
.unwrap_or_default();
match result {
Ok(value) if value > 0 => process(value),
Ok(_) => handle_zero(),
Err(e) => return Err(e.into()),
}
let Some(config) = load_config() else {
return Err(ConfigError::NotFound);
};
Project Structure
my-project/
โโโ Cargo.toml
โโโ src/
โ โโโ lib.rs # Library root
โ โโโ main.rs # Binary entry point
โ โโโ error.rs # Error types
โ โโโ modules/
โ โโโ mod.rs
โโโ tests/ # Integration tests
โโโ benches/ # Benchmarks
โโโ examples/ # Example programs
Error Handling
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AppError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("parse error: {message}")]
Parse { message: String },
#[error("not found: {0}")]
NotFound(String),
}
pub type Result<T> = std::result::Result<T, AppError>;
Common Crates
| Crate | Purpose |
|---|
serde | Serialization/deserialization |
tokio | Async runtime |
reqwest | HTTP client |
sqlx | Async SQL |
clap | CLI argument parsing |
tracing | Logging/diagnostics |
anyhow | Application errors |
thiserror | Library errors |
For detailed async patterns, unsafe code guidelines, WebAssembly compilation, embedded development, and advanced debugging, see REFERENCE.md.