Agent skill
Rust Ecosystem
This skill should be used when working with Rust projects, "Cargo.toml", "rustc", "cargo build/test/run", "clippy", "rustfmt", or Rust language patterns. Provides comprehensive Rust ecosystem patterns and best practices.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/rust-ecosystem-motoki317-dotfiles-2
SKILL.md
Rust Ecosystem
Core Concepts
- Ownership: Each value has one owner; when owner goes out of scope, value is dropped
- Borrowing:
&Tallows multiple immutable borrows;&mut Tallows exactly one; cannot mix - Result/Option:
Result<T, E>for recoverable errors,Option<T>for optional values; use?for propagation - Traits: Define behavior with traits; use
derivefor common implementations
Borrowing Rules
&T- multiple simultaneous immutable borrows allowed&mut T- exactly one mutable borrow allowed- Cannot have
&mut Twhile&Texists
Error Handling
// Custom error with thiserror
#[derive(Debug, thiserror::Error)]
enum MyError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Parse error: {msg}")]
Parse { msg: String },
}
// Propagate with ?
fn read_config() -> Result<Config, MyError> {
let content = std::fs::read_to_string("config.toml")?;
Ok(parse(content)?)
}
Common Traits
Clone- explicit.clone();Copy- implicit bitwise copyDebug-{:?}formatting;Display-{}formattingDefault- default value constructionPartialEq/Eq,PartialOrd/Ord- comparisonFrom/Into- type conversionsHash- for HashMap/HashSet keys
Project Structure
Cargo.toml
src/
lib.rs # Library crate root
main.rs # Binary crate root
bin/ # Additional binaries
tests/ # Integration tests
benches/ # Benchmarks
examples/ # Example code
Cargo.toml
[package]
name = "my-crate"
version = "0.1.0"
edition = "2021"
rust-version = "1.83"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
[lints.clippy]
pedantic = "warn"
unwrap_used = "deny"
[profile.release]
lto = true
codegen-units = 1
strip = true
Workspace
[workspace]
resolver = "2"
members = ["crate-a", "crate-b"]
[workspace.dependencies]
serde = "1.0"
tokio = { version = "1", features = ["full"] }
Member crates inherit with serde.workspace = true.
Anti-Patterns
- unwrap() in library code: Use
?or proper error handling - Clone abuse: Prefer borrowing when possible
- String for everything: Use enums, newtypes for domain modeling
- Arc<Mutex> overuse: Consider channels or ownership patterns first
Tools
cargo check- Fast syntax/type checkcargo clippy -- -D warnings- Lintercargo fmt- Formattercargo nextest run- Better test runnercargo audit- Security vulnerability scanningcargo tree- Dependency tree
rustfmt.toml
edition = "2021"
max_width = 100
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
Context7 Reference
- Rust Book:
/rust-lang/book - Cargo:
/rust-lang/cargo.git - Clippy:
/rust-lang/rust-clippy
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?