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
# Project setup
cargo new my-project # Binary crate
cargo new my-lib --lib # Library crate
cargo init # Initialize in existing directory
# From a template repo instead of an empty crate — see the cargo-generate skill
cargo generate --git <template-url> --name my-project
# Development workflow
cargo build # Debug build
cargo build --release # Optimized build
cargo run # Build and run
cargo run --release # Run optimized
cargo test # Run all tests
cargo test --lib # Library tests only
cargo bench # Run benchmarks
# Code quality
cargo clippy # Lint code
cargo clippy -- -W clippy::pedantic # Stricter lints
cargo fmt # Format code
cargo fmt --check # Check formatting
cargo fix # Auto-fix warnings
# Dependencies
cargo add serde --features derive # Add dependency
cargo update # Update deps
cargo audit # Security audit
cargo deny check # License/advisory check
# Advanced tools
cargo expand # Macro expansion
cargo flamegraph # Profile with flame graph
cargo doc --open # Generate and open docs
cargo miri test # Check for UB
# Cross-compilation
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown
Best Practices
Idiomatic Rust Patterns
// Use iterators over manual loops
let sum: i32 = numbers.iter().filter(|x| **x > 0).sum();
// Prefer combinators for Option/Result
let value = config.get("key")
.and_then(|v| v.parse().ok())
.unwrap_or_default();
// Use pattern matching effectively
match result {
Ok(value) if value > 0 => process(value),
Ok(_) => handle_zero(),
Err(e) => return Err(e.into()),
}
// Let-else for early returns
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.
1---
2created: 2025-12-16
3modified: 2026-05-09
4reviewed: 2026-04-25
5name: rust-development
6description: Rust development — cargo, clippy, rustfmt, async, Tokio, Serde, memory safety. Use when mentioning Rust, cargo, ownership, lifetimes, fearless concurrency, or async programming.
7user-invocable: false
8allowed-tools: Glob, Grep, Read, Bash, Edit, Write, TodoWrite, WebFetch, WebSearch
9---
10
11# Rust Development
12
13Expert knowledge for modern systems programming with Rust, focusing on memory safety, fearless concurrency, and zero-cost abstractions.
14
15## When to Use This Skill
16
17| Use this skill when... | Use sibling skill instead when... |
18|---|---|
19| Writing Rust code, ownership, lifetimes, async/await | Configuring lint rules in detail -- use `clippy-advanced` |
20| Choosing crates from the ecosystem (Tokio, Serde) | Detecting unused dependencies -- use `cargo-machete` |
21| Designing module structure or trait hierarchies | Running tests with parallel isolation -- use `cargo-nextest` |
22| Learning idiomatic Rust patterns and edition features | Generating coverage reports -- use `cargo-llvm-cov` |
23
24## Core Expertise
25
26**Modern Rust Ecosystem**
27- **Cargo**: Build system, package manager, and workspace management
28- **Rustc**: Compiler optimization, target management, and cross-compilation
29- **Clippy**: Linting for idiomatic code and performance improvements
30- **Rustfmt**: Consistent code formatting following Rust style guidelines
31- **Rust-analyzer**: Advanced IDE support with LSP integration
32
33**Language Features**
34- Rust 2024 edition: RPITIT, async fn in traits, impl Trait improvements
35- Const generics and compile-time computation
36- Generic associated types (GATs)
37- Let-else patterns and if-let chains
38
39## Key Capabilities
40
41**Ownership & Memory Safety**
42- Implement ownership patterns with borrowing and lifetimes
43- Design zero-copy abstractions and efficient memory layouts
44- Apply RAII patterns through Drop trait and smart pointers (Box, Rc, Arc)
45- Leverage interior mutability patterns (Cell, RefCell, Mutex, RwLock)
46- Use Pin/Unpin for self-referential structures
47
48**Async Programming & Concurrency**
49- **Tokio**: Async runtime for high-performance network applications
50- **async-std**: Alternative async runtime with familiar API design
51- **Futures**: Composable async abstractions and stream processing
52- **Rayon**: Data parallelism with work-stealing thread pools
53- Design lock-free data structures with atomics and memory ordering
54
55**Error Handling & Type Safety**
56- Design comprehensive error types with thiserror and anyhow
57- Implement Result<T, E> and Option<T> patterns effectively
58- Use pattern matching for exhaustive error handling
59- Apply type-state patterns for compile-time guarantees
60
61**Performance Optimization**
62- Profile with cargo-flamegraph, perf, and criterion benchmarks
63- Optimize with SIMD intrinsics and auto-vectorization
64- Implement zero-cost abstractions and inline optimizations
65- Use unsafe code judiciously with proper safety documentation
66
67**Testing & Quality Assurance**
68- **Unit Testing**: #[test] modules with assertions
69- **Integration Testing**: tests/ directory for end-to-end validation
70- **Criterion**: Micro-benchmarking with statistical analysis
71- **Miri**: Undefined behavior detection in unsafe code
72- **Fuzzing**: cargo-fuzz for security and robustness testing
73
74## Essential Commands
75
76```bash
77# Project setup
78cargo new my-project # Binary crate
79cargo new my-lib --lib # Library crate
80cargo init # Initialize in existing directory
81# From a template repo instead of an empty crate — see the cargo-generate skill
82cargo generate --git <template-url> --name my-project
83
84# Development workflow
85cargo build # Debug build
86cargo build --release # Optimized build
87cargo run # Build and run
88cargo run --release # Run optimized
89cargo test # Run all tests
90cargo test --lib # Library tests only
91cargo bench # Run benchmarks
92
93# Code quality
94cargo clippy # Lint code
95cargo clippy -- -W clippy::pedantic # Stricter lints
96cargo fmt # Format code
97cargo fmt --check # Check formatting
98cargo fix # Auto-fix warnings
99
100# Dependencies
101cargo add serde --features derive # Add dependency
102cargo update # Update deps
103cargo audit # Security audit
104cargo deny check # License/advisory check
105
106# Advanced tools
107cargo expand # Macro expansion
108cargo flamegraph # Profile with flame graph
109cargo doc --open # Generate and open docs
110cargo miri test # Check for UB
111
112# Cross-compilation
113rustup target add wasm32-unknown-unknown
114cargo build --target wasm32-unknown-unknown
115```
116
117## Best Practices
118
119**Idiomatic Rust Patterns**
120```rust
121// Use iterators over manual loops
122let sum: i32 = numbers.iter().filter(|x| **x > 0).sum();
123
124// Prefer combinators for Option/Result
125let value = config.get("key")
126 .and_then(|v| v.parse().ok())
127 .unwrap_or_default();
128
129// Use pattern matching effectively
130match result {
131 Ok(value) if value > 0 => process(value),
132 Ok(_) => handle_zero(),
133 Err(e) => return Err(e.into()),
134}
135
136// Let-else for early returns
137let Some(config) = load_config() else {
138 return Err(ConfigError::NotFound);
139};
140```
141
142**Project Structure**
143```
144my-project/
145├── Cargo.toml
146├── src/
147│ ├── lib.rs # Library root
148│ ├── main.rs # Binary entry point
149│ ├── error.rs # Error types
150│ └── modules/
151│ └── mod.rs
152├── tests/ # Integration tests
153├── benches/ # Benchmarks
154└── examples/ # Example programs
155```
156
157**Error Handling**
158```rust
159use thiserror::Error;
160
161#[derive(Error, Debug)]
162pub enum AppError {
163 #[error("IO error: {0}")]
164 Io(#[from] std::io::Error),
165
166 #[error("parse error: {message}")]
167 Parse { message: String },
168
169 #[error("not found: {0}")]
170 NotFound(String),
171}
172
173pub type Result<T> = std::result::Result<T, AppError>;
174```
175
176**Common Crates**
177| Crate | Purpose |
178|-------|---------|
179| `serde` | Serialization/deserialization |
180| `tokio` | Async runtime |
181| `reqwest` | HTTP client |
182| `sqlx` | Async SQL |
183| `clap` | CLI argument parsing |
184| `tracing` | Logging/diagnostics |
185| `anyhow` | Application errors |
186| `thiserror` | Library errors |
187
188For detailed async patterns, unsafe code guidelines, WebAssembly compilation, embedded development, and advanced debugging, see REFERENCE.md.