Agent Skill · Apollo GraphQL

rust-best-practices

Guide 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.

Provider: Apollo GraphQL Path in repo: skills/rust-best-practices/SKILL.md

Skill body

Rust Best Practices

Apply these guidelines when writing or reviewing Rust code. Based on Apollo GraphQL’s Rust Best Practices Handbook.

Best Practices Reference

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:

Quick Reference

Borrowing & Ownership

Error Handling

Performance

Linting

Run regularly: cargo clippy --all-targets --all-features --locked -- -D warnings

Key lints to watch:

Use #[expect(clippy::lint)] over #[allow(...)] with justification comment.

Testing

Generics & Dispatch

Type State Pattern

Encode 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 */ }
}

Documentation

Skill frontmatter

license: MIT compatibility: Rust 1.70+, Cargo metadata: {"author"=>"apollographql", "version"=>"1.1.0"} allowed-tools: Bash(cargo:*) Bash(rustc:*) Bash(rustfmt:*) Bash(clippy:*) Read Write Edit Glob Grep