Backend
501 installs
rust-best-practices
by apollographql/skills
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)…
Skill content
Idiomatic Rust coding standards based on Apollo GraphQL's best practices handbook. - Covers nine core areas: coding styles and idioms, clippy linting, performance optimization, error handling, testing patterns, generics and dispatch, type state pattern, documentation, and pointer safety - Emphasizes borrowing over cloning, Result-based error handling with thiserror/anyhow, and performance profiling with release builds - Includes quick reference guidance on ownership patterns, panic avoidance, clippy configuration, test naming conventions, and compile-time state safety via type state pattern - Provides specific lints to enforce (redundant_clone, large_enum_variant, needless_collect) and recommends #[expect(...)] over #[allow(...)] with justification comments 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: - Chapter 1 - Coding Styles and Idioms: Borrowing vs cloning, Copy trait, Option/Result handling, iterators, comments - Chapter 2 - Clippy and Linting: Clippy configuration, important lints, workspace lint setup - Chapter 3 - Performance Mindset: Profiling, avoiding redundant clones, stack vs heap, zero-cost abstractions - Chapter 4 - Error Handling: Result vs panic, thiserror vs anyhow, error hierarchies - Chapter 5 - Automated Testing: Test naming, one assertion per test, snapshot testing - Chapter 6 - Generics and Dispatch: Static vs dynamic dispatch, trait objects - Chapter 7 - Type State Pattern: Compile-time state safety, when to use it - Chapter 8 - Comments vs Documentation: When to comment, doc comments, rustdoc - Chapter 9 - Understanding Pointers: Thread safety, Send/Sync, pointer types Quick Reference