Files
worklane/docs/rust-style.md
T

12 lines
986 B
Markdown

# Rust Style
The small conventions this tree keeps in its Rust.
- Use `if matches!(expr, Variant)` instead of `if let Some(Variant) = expr` for enum variant matching
- Use `if let Some(x) = expr` instead of `if let Some(Some(x)) = expr` — drop unnecessary nesting
- Prefer explicit `match` over `unwrap_or_default()` for clarity
- Use `unwrap_or_else(|| expr)` for lazy defaults, `unwrap_or(val)` for eager defaults
- Use `anyhow!()` with context strings that include identifying info (e.g. UUID, title) not bare values
- A command whose arguments run past a handful takes a clap `Args` struct, not an inline variant with a matching parameter list: `AddArgs`, `SetArgs`, `AppendArgs`, `CheckArgs`, `MvArgs`. `add` was nine positional parameters threaded from `main` before it became `AddArgs`, and the handler destructures the struct so the body reads the same as before. `mv` was the last inline variant to carry an `--actor`, and `--actor-from-git` pushed its list past the line