Rust Compiler Skill
This skill optimizes Rust compilation workflows to minimize token consumption while maintaining full visibility into errors and warnings.
Core Principle
For most development tasks use the rust lsp (rust-analyzer) for real-time feedback. When you need to compile or run tests, use the following patterns to capture only relevant output while discarding verbose messages.
Rust compiler output can be extremely verbose, especially for successful builds or when downloading dependencies. Redirect stdout to /dev/null while preserving stderr for actual errors and warnings.
Essential Commands
Compilation Check (Fastest Feedback)
cargo check 2>&1 >/dev/null | head -100
Use cargo check instead of cargo build when you only need to verify code compiles. It skips code generation and is significantly faster.
Building Code
cargo build 2>&1 >/dev/null | head -100
For release builds:
cargo build --release 2>&1 >/dev/null | head -100
Clippy Linting
cargo clippy 2>&1 >/dev/null | head -100
Always run clippy after making changes. All warnings must be addressed.
Running Tests
cargo test 2>&1 >/dev/null | head -150
For a specific test:
cargo test test_name 2>&1 >/dev/null | head -100
For a specific crate in a workspace:
cargo test -p crate-name 2>&1 >/dev/null | head -100
Formatting
cargo fmt --all
Always run after editing Rust files. No output redirection needed as it produces minimal output.
Workspace-Specific Commands
For large workspaces, target specific crates to reduce compilation scope:
# Check a specific crate
cargo check -p crate-name 2>&1 >/dev/null | head -100
# Build a specific binary
cargo build --bin binary-name 2>&1 >/dev/null | head -100
# Run clippy on a specific crate
cargo clippy -p crate-name 2>&1 >/dev/null | head -100
Error Investigation
When errors occur, you may need more context. Use these patterns:
# Get more error lines if truncated
cargo check 2>&1 >/dev/null | head -200
# See full error for a specific issue
cargo check 2>&1 >/dev/null | grep -A 20 "error\[E"
# Count total errors
cargo check 2>&1 >/dev/null | grep -c "^error"
Recommended Workflow
- After writing/editing code: Run
cargo fmt --all - Quick validation: Run
cargo check -p <crate> 2>&1 >/dev/null | head -100 - Before committing: Run
cargo clippy 2>&1 >/dev/null | head -100 - For tests: Run
cargo test -p <crate> 2>&1 >/dev/null | head -150
Why Truncate Output?
- Successful cargo builds can produce thousands of lines of "Compiling..." messages
- Downloading dependencies generates extensive output
- Using
head -100orhead -150captures errors while avoiding token bloat - The pattern
2>&1 >/dev/nullredirects stderr to the pipe while discarding stdout, ensuring only errors and warnings are captured
