Rust Best Practices

Stuurt Rust code naar idiomatische error handling, borrowing, iterators en async patterns

Door majiayu000 · majiayu000/spellbook

Getest · Werkt ★ 8.8/10

Rust Best Practices — Stuurt Rust code naar idiomatische error handling, borrowing, iterators en async patterns

Wat het doet

Begeleidende skill die Rust code stuurt naar idiomatische patronen: Result/thiserror error handling, borrowing over ownership, iterators, geen unwrap, en cargo/clippy/tokio conventies. Activeert bij het schrijven, beoordelen of optimaliseren van Rust code of bij het omgaan met lifetimes, de borrow checker en async Rust.

Testrapport

SKILL.md raw opgehaald (HTTP 200); frontmatter parseert met name+description en allowed-tools. Body is volledig zelfstandig — geen bestand/script referenties om steekproefsgewijs te controleren, geen security smells (geen curl|sh, base64, exfiltration, of injection text), geen hardcoded paths. Trigger zinsneden — MOET (allemaal beoordeeld als laden): "fix this borrow checker error in my Rust struct", "write an async tokio function to download files concurrently in Rust", "review my Rust crate's error handling and make it more idiomatic"; MOET NIET (beide beoordeeld als overslaan): "optimize my Python script's memory usage" (memory/optimize maar geen Rust), "explain the history of the Rust programming language" (Rust genoemd maar geen code schrijven/beoordelen/optimaliseren) — 5/5. Output test: een get_port config parser op twee manieren geschreven in /tmp scratchpad (baseline.rs, skill.rs). Baseline panikeert bij onjuiste input (parts[1] index + parse().unwrap()) en retourneert stilzwijgend 0 bij ontbrekende poort; skill versie — de body strikt volgend — neemt &str, retourneert Result<u16, ConfigError> via een thiserror enum, gebruikt split_once/find_map iterators, geen unwrap, en voegt 3 #[cfg(test)] tests toe. Zes concrete verschillen, elk terug te voeren op een skill regel. Geen rustc/cargo beschikbaar dus ik heb niet gecompileerd (skill versie gebruikt thiserror); logica geverifieerd door tracing. Docs grotendeels accuraat, maar de "Microsoft Pragmatic Rust Guidelines" attributie overdrijft generiek idiomatisch-Rust advies, wat één docs punt kost.

Getest op: 2026-07-31 · Claude Code 2.x (agent harness)

Installatie

git clone --depth 1 https://github.com/majiayu000/spellbook.git /tmp/rust-best-practices-src
mkdir -p ~/.claude/skills/rust-best-practices
cp /tmp/rust-best-practices-src/plugins/rust-dev/skills/rust-best-practices.SKILL.md ~/.claude/skills/rust-best-practices/SKILL.md
# NOTE: nonstandard layout in repo — the skill is a flat file `rust-best-practices.SKILL.md`
#       (not a directory), so the cp above renames it to SKILL.md at the correct path.
# Self-contained: no scripts, references, or external deps. Guidance-only skill.
# Plugin-marketplace alternative: the repo ships a `rust-dev` plugin
#   (plugins/rust-dev/.claude-plugin/plugin.json) that also bundles this skill.

Commando's en voorbeeldprompts

  • /rust-best-practicesStuurt Rust code naar idiomatische error handling, borrowing, iterators en async patterns

Skills reageren op gewone verzoeken — geen commando's om te onthouden. Na installatie activeren prompts zoals deze de skill (in het Engels):

  • Review this Rust code for idiomatic patterns
  • Fix this borrow checker error in my function
  • Optimize this async Rust code for performance