Rust Developer Skill
Overview
Use this skill when acting as a Lead Rust Developer on the tbdflow codebase. It targets Rust 2021 edition, Clap 4.x for
CLI argument parsing, anyhow/thiserror for error handling, and serde for serialization. The goal is to ensure idiomatic
Rust, safe and ergonomic APIs, and pragmatic application code that stays aligned with the TBD workflow.
When to Use
- Implementing or reviewing Rust CLI features, commands, or module structure.
- Designing error handling strategies, Result chains, or custom error types.
- Producing configuration structs, validators, or parsing constructs in Rust.
- Guiding architectural or style decisions for CLI tools within this repo.
When Not to Use
- Web frontend, WASM UI, or non-Rust services.
- Infrastructure-as-code, Terraform, or pure documentation tasks.
- Situations where another specialised skill (e.g.,
tbdflow workflow) already governs the process.
Instructions
General Guidance
- Always read
Cargo.toml before suggesting dependencies or versions.
- Use idiomatic Rust: ownership, borrowing, lifetimes, pattern matching, and iterators.
- Default to immutable bindings (
let) and leverage the type system for safety.
- Avoid
.unwrap() and .expect() in library code; use ? operator and proper error propagation.
- Prefer
Result<T, E> over panics; reserve panics for truly unrecoverable states.
- Treat tests as first-class: unit tests in modules, integration tests in
tests/.
Preferred Practices
- Follow Clap derive conventions; keep command handlers thin and delegate to domain modules.
- Use the module system effectively:
mod.rs or inline modules, clear public API boundaries.
- Leverage iterators and combinators (
.map(), .filter(), .collect()) over manual loops.
- Keep functions/files concise; split modules when responsibilities grow complex.
- Use
cargo clippy and cargo fmt for linting and formatting.
Patterns to Follow
Error Handling: Use thiserror for custom error types in libraries, anyhow for applications.
// Library error with thiserror
#[derive(Error, Debug)]
pub enum GitError {
#[error("Git command failed: {0}")]
CommandFailed(String),
#[error("Branch '{0}' not found")]
BranchNotFound(String),
}
// Application code with anyhow
fn main() -> anyhow::Result<()> {
let config = load_config().context("Failed to load configuration")?;
Ok(())
}
Structs & Enums: Use #[derive] liberally for common traits.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Config {
pub name: String,
#[serde(default)]
pub enabled: bool,
}
Option/Result Handling: Prefer combinators and ? over explicit matching.
// Preferred
let name = config.name.as_ref().map(|s| s.trim()).unwrap_or("default");
// Also good with ?
let value = some_option.ok_or_else(|| anyhow!("Missing value"))?;
CLI Structure: Use Clap derive with clear subcommands and help text.
#[derive(Parser)]
#[command(name = "mytool", about = "Does useful things")]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(long, global = true)]
verbose: bool,
}
Testing: Use #[cfg(test)] modules and descriptive test names.
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_config_with_defaults() {
let config: Config = serde_yaml::from_str("name: test").unwrap();
assert!(!config.enabled);
}
}
Patterns to Avoid
- Unwrap Abuse: Avoid
.unwrap() except in tests or when invariants are proven.
- Clone Overuse: Don't
.clone() to satisfy the borrow checker without understanding why.
- Stringly Typed: Use enums and newtypes instead of raw strings for domain concepts.
- God Modules: Avoid modules with 500+ lines; split into focused submodules.
- Ignoring Clippy: Address warnings; they often catch real issues.
- Blocking in Async: If using async, don't call blocking APIs without
spawn_blocking.
Tooling & Dependency Checks
- Confirm crate versions from
Cargo.toml and Cargo.lock before adding dependencies.
- Prefer well-maintained crates from the ecosystem (check crates.io downloads, recent updates).
- Use
cargo test for unit/integration tests; cargo test --doc for doc tests.
- Maintain test coverage on critical logic; structure tests with Arrange-Act-Assert.
- Run
cargo clippy -- -W clippy::pedantic periodically for deeper analysis.
- Use
cargo audit to check for security vulnerabilities in dependencies.
Output Expectations
- Document public APIs with doc comments (
///) focusing on usage and rationale.
- Include examples in doc comments for complex functions.
- Keep guidance inclusive, action-oriented, and practical.
- When suggesting new dependencies, justify the addition and check for existing alternatives.
Module Organization (tbdflow example)
src/
├── lib.rs # Public module exports
├── main.rs # CLI entry point, command dispatch
├── cli.rs # Clap definitions (Commands enum)
├── config.rs # Configuration structs and loading
├── git.rs # Git operations (shell out to git)
├── commit.rs # Commit workflow logic
├── branch.rs # Branch management
├── review.rs # Review feature
└── wizard.rs # Interactive prompts
- Keep
main.rs thin: parse args, load config, dispatch to handlers.
- Domain logic lives in dedicated modules (
commit.rs, branch.rs).
- Shared utilities go in
misc.rs or a utils/ submodule.
Notes
- This skill complements, but does not override, the
tbdflow Git workflow skill—use both where applicable.
- If unsure about a pattern or crate, design a small experiment first (write a test) before implementing.
- Consult Rust API Guidelines for naming and design decisions.
- Reference The Rust Book for fundamentals.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: rust-developer-23description: Lead Rust developer guidance for Rust 2021+, Clap CLI applications, error handling with anyhow/thiserror, and idiomatic patterns. Use when this capability is needed.4---56# Rust Developer Skill78## Overview910Use this skill when acting as a Lead Rust Developer on the tbdflow codebase. It targets Rust 2021 edition, Clap 4.x for11CLI argument parsing, anyhow/thiserror for error handling, and serde for serialization. The goal is to ensure idiomatic12Rust, safe and ergonomic APIs, and pragmatic application code that stays aligned with the TBD workflow.1314## When to Use1516- Implementing or reviewing Rust CLI features, commands, or module structure.17- Designing error handling strategies, Result chains, or custom error types.18- Producing configuration structs, validators, or parsing constructs in Rust.19- Guiding architectural or style decisions for CLI tools within this repo.2021## When Not to Use2223- Web frontend, WASM UI, or non-Rust services.24- Infrastructure-as-code, Terraform, or pure documentation tasks.25- Situations where another specialised skill (e.g., `tbdflow` workflow) already governs the process.2627## Instructions2829### General Guidance3031- Always read `Cargo.toml` before suggesting dependencies or versions.32- Use idiomatic Rust: ownership, borrowing, lifetimes, pattern matching, and iterators.33- Default to immutable bindings (`let`) and leverage the type system for safety.34- Avoid `.unwrap()` and `.expect()` in library code; use `?` operator and proper error propagation.35- Prefer `Result<T, E>` over panics; reserve panics for truly unrecoverable states.36- Treat tests as first-class: unit tests in modules, integration tests in `tests/`.3738### Preferred Practices3940- Follow Clap derive conventions; keep command handlers thin and delegate to domain modules.41- Use the module system effectively: `mod.rs` or inline modules, clear public API boundaries.42- Leverage iterators and combinators (`.map()`, `.filter()`, `.collect()`) over manual loops.43- Keep functions/files concise; split modules when responsibilities grow complex.44- Use `cargo clippy` and `cargo fmt` for linting and formatting.4546### Patterns to Follow4748- **Error Handling**: Use `thiserror` for custom error types in libraries, `anyhow` for applications.49 ```rust50 // Library error with thiserror51 #[derive(Error, Debug)]52 pub enum GitError {53 #[error("Git command failed: {0}")]54 CommandFailed(String),55 #[error("Branch '{0}' not found")]56 BranchNotFound(String),57 }58 59 // Application code with anyhow60 fn main() -> anyhow::Result<()> {61 let config = load_config().context("Failed to load configuration")?;62 Ok(())63 }64 ```6566- **Structs & Enums**: Use `#[derive]` liberally for common traits.67 ```rust68 #[derive(Debug, Clone, Serialize, Deserialize, Default)]69 pub struct Config {70 pub name: String,71 #[serde(default)]72 pub enabled: bool,73 }74 ```7576- **Option/Result Handling**: Prefer combinators and `?` over explicit matching.77 ```rust78 // Preferred79 let name = config.name.as_ref().map(|s| s.trim()).unwrap_or("default");80 81 // Also good with ?82 let value = some_option.ok_or_else(|| anyhow!("Missing value"))?;83 ```8485- **CLI Structure**: Use Clap derive with clear subcommands and help text.86 ```rust87 #[derive(Parser)]88 #[command(name = "mytool", about = "Does useful things")]89 struct Cli {90 #[command(subcommand)]91 command: Commands,92 #[arg(long, global = true)]93 verbose: bool,94 }95 ```9697- **Testing**: Use `#[cfg(test)]` modules and descriptive test names.98 ```rust99 #[cfg(test)]100 mod tests {101 use super::*;102 103 #[test]104 fn parse_config_with_defaults() {105 let config: Config = serde_yaml::from_str("name: test").unwrap();106 assert!(!config.enabled);107 }108 }109 ```110111### Patterns to Avoid112113- **Unwrap Abuse**: Avoid `.unwrap()` except in tests or when invariants are proven.114- **Clone Overuse**: Don't `.clone()` to satisfy the borrow checker without understanding why.115- **Stringly Typed**: Use enums and newtypes instead of raw strings for domain concepts.116- **God Modules**: Avoid modules with 500+ lines; split into focused submodules.117- **Ignoring Clippy**: Address warnings; they often catch real issues.118- **Blocking in Async**: If using async, don't call blocking APIs without `spawn_blocking`.119120### Tooling & Dependency Checks121122- Confirm crate versions from `Cargo.toml` and `Cargo.lock` before adding dependencies.123- Prefer well-maintained crates from the ecosystem (check crates.io downloads, recent updates).124- Use `cargo test` for unit/integration tests; `cargo test --doc` for doc tests.125- Maintain test coverage on critical logic; structure tests with Arrange-Act-Assert.126- Run `cargo clippy -- -W clippy::pedantic` periodically for deeper analysis.127- Use `cargo audit` to check for security vulnerabilities in dependencies.128129### Output Expectations130131- Document public APIs with doc comments (`///`) focusing on usage and rationale.132- Include examples in doc comments for complex functions.133- Keep guidance inclusive, action-oriented, and practical.134- When suggesting new dependencies, justify the addition and check for existing alternatives.135136### Module Organization (tbdflow example)137138```139src/140├── lib.rs # Public module exports141├── main.rs # CLI entry point, command dispatch142├── cli.rs # Clap definitions (Commands enum)143├── config.rs # Configuration structs and loading144├── git.rs # Git operations (shell out to git)145├── commit.rs # Commit workflow logic146├── branch.rs # Branch management147├── review.rs # Review feature148└── wizard.rs # Interactive prompts149```150151- Keep `main.rs` thin: parse args, load config, dispatch to handlers.152- Domain logic lives in dedicated modules (`commit.rs`, `branch.rs`).153- Shared utilities go in `misc.rs` or a `utils/` submodule.154155## Notes156157- This skill complements, but does not override, the `tbdflow` Git workflow skill—use both where applicable.158- If unsure about a pattern or crate, design a small experiment first (write a test) before implementing.159- Consult [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/) for naming and design decisions.160- Reference [The Rust Book](https://doc.rust-lang.org/book/) for fundamentals.161162---163> Converted and distributed by [TomeVault](https://tomevault.io/claim/cladam) — claim your Tome and manage your conversions.164<!-- tomevault:4.0:skill_md:2026-04-11 -->