| name | rust |
| description | Use cargo for Rust development with check-first workflow. Prefer cargo check over cargo build, use debug builds for testing, AVOID release builds unless explicitly needed. |
Rust/Cargo Development Skill
You are a Rust development specialist using cargo and related tools. This skill provides comprehensive workflows, best practices, and common patterns for Rust development.
IMPORTANT: Build Strategy
AVOID expensive builds:
- DON'T use
cargo build --release or cargo install --path . (very slow)
- DON'T build unless necessary - use
cargo check first
- DO use
cargo check to verify compilation (fast, no codegen)
- DO use
cargo run for iterative development and testing functionality (builds debug + runs in one command)
- DO use debug builds for testing binaries (
cargo build without --release)
Decision tree:
- Just checking if code compiles? →
cargo check (fastest)
- Developing/testing functionality? →
cargo run (builds debug + runs - use this for iteration)
- Need the binary artifact without running? →
cargo build (debug)
- Need optimized performance? → Only then use
cargo build --release (slow)
Standard Development Workflow
Command Execution Order
Always follow this sequence when developing or validating Rust code:
cargo test --quiet
cargo check --quiet
cargo clippy
IMPORTANT: Use cargo check, NOT cargo build, for validation. Only use cargo build when you actually need the binary artifact.
For iterative development and testing functionality:
cargo run
cargo run -- arg1 arg2
cargo build --quiet
Rationale:
- Tests first: Catch logic errors early
- Check second: Fast compilation verification without codegen
- Clippy third: Address code quality and style issues
- Run/Build last: Use
cargo run to iterate on functionality, or cargo build if you need the artifact
Timeout Settings
Rust commands can be long-running, especially for large projects:
cargo test --quiet
cargo check --quiet
cargo build --quiet
cargo build --release
Best practice: Use the standard 2-minute timeout for check/test/debug builds. Only use extended timeout if you absolutely must do a release build.
Clippy - Linting and Code Quality
Auto-fix Workflow
Always attempt automatic fixes first:
cargo clippy --fix --allow-dirty
Flags:
--fix: Automatically apply suggested fixes
--allow-dirty: Allow fixes even with uncommitted changes
- Implies
--no-deps and --all-targets
Clippy Strategies
1. Distinguish Warning Types
Separate actionable issues from domain-appropriate patterns:
Actionable bugs:
- Logic errors
- Potential panics
- Memory safety issues
- API misuse
Domain-appropriate suppressions:
- Domain-specific patterns (e.g.,
cast_possible_truncation in Excel formula evaluators)
- False positives (e.g.,
unused_assignments for loop invariants)
- Documentation lints for internal tools (e.g.,
missing_errors_doc)
- Style preferences that don't affect correctness (e.g.,
needless_pass_by_value)
2. Suppression Hierarchy
Function-level suppression:
#[allow(clippy::cast_possible_truncation)]
fn process_excel_value(val: u64) -> u32 {
val as u32
}
Module-level suppression (top of file):
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::cast_possible_truncation)]
Project-level suppression (Cargo.toml):
[lints.clippy]
missing_errors_doc = "allow"
cast_possible_truncation = "allow"
needless_pass_by_value = "allow"
3. Systematic Approach
- Run
cargo clippy to see all warnings
- Run
cargo clippy --fix --allow-dirty to auto-fix
- Review remaining warnings and categorize:
- Fix: Legitimate issues
- Suppress: Domain-specific or false positives
- Add strategic suppressions at appropriate level
- Result: Only actionable warnings remain
Common Clippy Lints to Consider
Often suppressed in domain-specific code:
cast_possible_truncation - When domain guarantees safety
cast_sign_loss - When values are known positive
missing_errors_doc - Internal tools/libraries
missing_panics_doc - When panics are domain-impossible
needless_pass_by_value - API design choices
module_name_repetitions - Sometimes necessary for clarity
too_many_lines - Large but cohesive functions
unused_assignments - Loop invariants and initialization patterns
Generally should fix:
redundant_closure - Simplify code
unnecessary_unwrap - Handle errors properly
manual_map - Use iterator methods
match_same_arms - Reduce duplication
needless_return - Clean up style
Explaining Lints
Get detailed information about any lint:
cargo clippy --explain <LINT_NAME>
Command-line Lint Control
cargo clippy -- -W clippy::unwrap_used
cargo clippy -- -D clippy::unwrap_used
cargo clippy -- -A clippy::needless_pass_by_value
cargo clippy -- -F clippy::unwrap_used
Common Cargo Commands
Checking (Prefer This)
cargo check
cargo check --quiet
cargo check --all-targets
Use cargo check instead of cargo build when you just need to verify code compiles.
Building
cargo build
cargo build --quiet
cargo build --all-targets
cargo build --target <TARGET>
cargo build --release
Testing
cargo test
cargo test --quiet
cargo test <NAME>
cargo test --lib
cargo test --doc
cargo test -- --nocapture
cargo test -- --test-threads=1
Running
cargo run
cargo run --bin <NAME>
cargo run --example <NAME>
cargo run -- <ARGS>
cargo run --release
Documentation
cargo doc
cargo doc --open
cargo doc --no-deps
Dependency Management
cargo add <CRATE>
cargo add <CRATE>@<VERSION>
cargo add --dev <CRATE>
cargo remove <CRATE>
cargo update
cargo update <CRATE>
Project Management
cargo new <NAME>
cargo new --lib <NAME>
cargo init
cargo clean
Publishing and Package Info
cargo search <QUERY>
cargo publish
cargo package
cargo tree
Process Management
Cleaning Up Background Processes
Cargo can leave processes running that cause "resource busy" or lock errors:
pkill -f cargo
Use this before running cargo commands if you encounter:
- "resource busy" errors
- Cargo.lock contention
- Build hanging
- File lock errors
Common Lock Issues
Problem: Multiple cargo processes fighting for Cargo.lock
Solution:
pkill -f cargo
cargo clean
cargo build
Configuration Best Practices
Cargo.toml Comments
Place comments on separate lines, not inline:
Correct:
clap = "4.0"
[lints.clippy]
cast_possible_truncation = "allow"
Incorrect:
clap = "4.0"
cast_possible_truncation = "allow"
Lint Configuration Structure
[lints.clippy]
unwrap_used = "warn"
expect_used = "warn"
cast_possible_truncation = "allow"
missing_errors_doc = "allow"
needless_pass_by_value = "allow"
module_name_repetitions = "allow"
Complete Development Workflows
Workflow 1: New Feature Development
git checkout -b feature/new-thing
cargo test --quiet
cargo check --quiet
cargo clippy
cargo clippy --fix --allow-dirty
cargo test --quiet
cargo check --quiet
cargo clippy
git add .
git commit -m "Add new feature"
Workflow 2: Fixing Clippy Warnings
cargo clippy
cargo clippy --fix --allow-dirty
cargo clippy
cargo clippy
cargo test --quiet
Workflow 3: Debugging Build Issues
cargo clean
pkill -f cargo
cargo check
cargo build --verbose
cargo check --lib
cargo check --tests
Workflow 4: Dependency Updates
cargo tree
cargo update
cargo update serde
cargo test --quiet
cargo check --quiet
cargo clippy
git diff Cargo.lock
Workflow 5: Pre-commit Validation
cargo test --quiet && cargo check --quiet && cargo clippy
Performance Optimization
Build Performance
cargo check
cargo build -j 8
cargo build --release --locked
Development tip: cargo check is 2-10x faster than cargo build and sufficient for most development.
Test Performance
cargo test --lib
cargo test --lib --bins
cargo test module_name::
Common Patterns and Tips
Pattern 1: Iterative Development
cargo check
cargo check
cargo test --quiet
Pattern 2: Release Preparation (ONLY for actual releases)
WARNING: Only use this workflow when preparing an actual release. For regular development, use the check-first workflow.
cargo test
cargo test --release
cargo build --release
cargo clippy -- -D warnings
cargo doc --no-deps
For regular development, use instead:
cargo test --quiet
cargo check --quiet
cargo clippy
Pattern 3: Multi-target Projects
cargo check --all-targets
cargo test --all-targets
cargo clippy --all-targets
Pattern 4: Documentation Testing
cargo test --doc
cargo doc --open
Error Handling
Common Issues and Solutions
Issue: "could not compile due to previous error"
cargo clean
cargo build
Issue: "waiting for file lock on package cache"
pkill -f cargo
Issue: Clippy warnings overwhelming
cargo clippy --fix --allow-dirty
Issue: Tests passing but clippy failing
cargo clippy --fix --allow-dirty
Quick Reference
cargo test --quiet && cargo check --quiet && cargo clippy
cargo clippy --fix --allow-dirty
pkill -f cargo && cargo clean && cargo check
cargo update && cargo test --quiet && cargo check --quiet
cargo doc --open
cargo add <crate>
cargo check
cargo build
Integration with Git
After validation, use the git commit message writer agent:
- Captures comprehensive commit context
- Follows project conventions
- Professional, human-written style (no AI attribution per CLAUDE.md)
git add .