14 skills · 41 min
Skills
Skill 13 of 14
Guide for writing idiomatic Rust code based on Apollo GraphQL’s best practices handbook.
1 minute · 316 words · 10 sections
Install
npx skills add apollographql/skills --skill rust-best-practicesnpx skills add apollographql/skills/plugin marketplace add apollographql/skillsThe first command installs just this skill, by the name in its SKILL.md; the second installs the whole repository.
Apply these guidelines when writing or reviewing Rust code. Based on Apollo GraphQL’s Rust Best Practices Handbook (opens in a new tab).
Before reviewing, familiarize yourself with Apollo’s Rust best practices. Read ALL relevant chapters in the same turn in parallel. Reference these files when providing feedback:
&T over .clone() unless ownership transfer is required&str over String, &[T] over Vec<T> in function parametersCopy types (≤24 bytes) can be passed by valueCow<'_, T> when ownership is ambiguousResult<T, E> for fallible operations; avoid panic! in productionunwrap()/expect() outside teststhiserror for library errors, anyhow for binaries only? operator over match chains for error propagation--release flagcargo clippy -- -D clippy::perf for performance hints.iter() instead of .into_iter() for Copy types.collect() callsRun regularly: cargo clippy --all-targets --all-features --locked -- -D warnings
Key lints to watch:
redundant_clone - unnecessary cloninglarge_enum_variant - oversized variants (consider boxing)needless_collect - premature collectionUse #[expect(clippy::lint)] over #[allow(...)] with justification comment.
process_should_return_error_when_input_empty()///) for public API examplescargo insta for snapshot testing generated outputdyn Trait only when heterogeneous collections are neededEncode valid states in the type system to catch invalid operations at compile time:
struct Connection<State> { /* ... */ _state: PhantomData<State> }
struct Disconnected;
struct Connected;
impl Connection<Connected> {
fn send(&self, data: &[u8]) { /* only connected can send */ }
// comments explain why (safety, workarounds, design rationale)/// doc comments explain what and how for public APIsTODO needs a linked issue: // TODO(#42): ...#![deny(missing_docs)] for librariesGuide for writing idiomatic Rust code based on Apollo GraphQL's best practices handbook. Use this skill when: (1) writing new Rust code or functions, (2) reviewing or refactoring existing Rust code, (3) deciding between borrowing vs cloning or ownership patterns, (4) implementing error handling with Result types, (5) optimizing Rust code for performance, (6) writing tests or documentation for Rust projects.
The verbatim description from this skill’s front matter — the string an agent matches on to decide whether to load it.
Bash(cargo:*)Bash(rustc:*)Bash(rustfmt:*)Bash(clippy:*)ReadWriteEditGlobGrepskills/rust-best-practices/SKILL.mdmain, last pushed 23 September 2026.SKILL.md, not by matching a directory convention. One layout observed: skills/*/SKILL.md.h1 and no skipped levels:.claude-plugin/marketplace.json by Apollo GraphQL, declaring 1 plugin. It is read for editorial metadata only — never as the skill index, which is always the repository tree./apollographql/skills.md, and each skill at its own URL..md9 files · 94 KB
Everything this skill ships beside its prose. All of it is set here, as subchapters of skill 13.
Documentation the agent loads on demand, rather than up front.