rust-code-review

Checkliste und Entscheidungsrahmen für Rust-Code-Reviews von Rust-PRs, abgeleitet von rust-best-practices.

npx skills add https://github.com/apollographql/rust-best-practices --skill rust-code-review

Rust Code Review

Use this for Rust review work where consistency, safety, and maintainability matter.

Follow ths standards in https://github.com/apollographql/rust-best-practices

Mandatory pre-merge checks

  • Ownership and data flow are intentional.
  • Error handling is explicit and aligns with crate/binary boundaries.
  • Clippy and format quality are clean in touched files.
  • Performance changes are measured before acceptance.
  • Public APIs are documented; docs match runtime behavior.
  • Tests cover intended behavior and error paths.
  • Unsafe or raw-pointer usage is justified and constrained.

Severity matrix

  • P0: unsafe memory bug, panic in recoverable production path, silent data corruption.
  • P1: correctness bug, missing error propagation, invalid API contract.
  • P2: likely performance regression, missing public API docs, flaky tests.
  • P3: style/readability issues, avoidable clone/allocation, unnecessary complexity.

Review skills

Ownership-first coding

  • Prefer borrowing (&T, &mut T) over cloning.
  • Use Clone only when ownership is required or snapshots are explicitly needed.
  • Treat unnecessary clones (especially in loops) as likely regressions.
  • Reject clone on Copy types.

Value vs reference

  • Pass Copy/small POD types by value.
  • Pass large heap-backed or non-trivial objects by reference.
  • Surface ownership intent in function signatures.
  • Use Cow<'_, T> when input may be borrowed or owned.

Fallible control flow

  • Use let PATTERN = EXPR else { ... } for expected early exits.
  • Use if let ... else when divergence needs additional logic.
  • Prefer ? for bubbling errors.
  • Avoid unwrap/expect in production except when impossible-by-design cases are documented.

Allocation and allocation timing

  • Prefer _else APIs to avoid eager allocation (ok_or_else, map_or_else, etc.).
  • Keep iterator chains lazy; allocate only when required by terminal ops.
  • Do not collect and allocate only to throw away data.

Iterator vs loop

  • Use iterator chains for data transformation and composition.
  • Use for for early exits and side-effect-heavy or control-heavy loops.
  • Require readable formatting; avoid long unreadable chains.

Lints and static checks

  • Run and fix warnings from:
    • cargo clippy --all-targets --all-feature --locked -- -D warnings
  • Do not globally silence useful lints.
  • Prefer #[expect(clippy::...)] with rationale instead of #[allow(...)] unless fully justified.

Error discipline

  • Libraries: prefer typed errors (thiserror and #[from] conversions).
  • Binaries: anyhow acceptable, but keep context rich and actionable.
  • Test both success and error behavior.

Tests as behavior docs

  • One behavior per test.
  • One core assertion per test where possible.
  • Names should be descriptive sentence-like statements.
  • Prefer unit tests for internals, integration tests for public behavior.
  • Use snapshot tests only for complex, stable structured outputs.

Documentation and comments

  • Use //////! for API behavior and constraints.
  • Use // for why, safety rationale, platform constraints, and assumptions.
  • Remove stale comments; prefer smaller functions over narrative comments.
  • Link TODOs to issues instead of leaving bare TODO:.

Pointers and concurrency

  • Prefer &/&mut before any heap pointer.
  • Use Arc for cross-thread shared ownership; Rc for single-threaded.
  • Use Box for recursive/heap allocation needs.
  • Review raw pointer usage as unsafe boundaries with explicit invariants.

Quick rejection triggers

  • Unnecessary clones in hot paths.
  • Unjustified allow(clippy::...).
  • Silent recovery from Err that discards root cause.
  • Copying large types by value without a proof of intent.
  • Comments that simply restate what code already expresses.
  • TODOs without ownership/context.

Mehr Skills von apollographql

apollo-federation
apollographql
Apollo Federation ermöglicht das Zusammenführen mehrerer GraphQL-APIs (Subgraphen) zu einem einheitlichen Supergraphen.
apollo-ios
apollographql
Apollo iOS ist ein stark typisierter GraphQL-Client für Apple-Plattformen. Er generiert Swift-Typen aus Ihren GraphQL-Operationen und Ihrem Schema und enthält einen Async/Await-Client, einen normalisierten Cache (im Arbeitsspeicher oder SQLite-gestützt), einen steckbaren, auf Interceptoren basierenden HTTP-Transport, der Abfragen, Mutationen und Multipart-Abonnements verarbeitet, sowie einen optionalen WebSocket-Transport (graphql-transport-ws), der jeden Operationstyp übertragen kann.
apollo-router
apollographql
Apollo Router ist ein leistungsstarker Graph-Router, der in Rust geschrieben wurde und für den Betrieb von Apollo Federation 2-Supergraphen entwickelt wurde. Er sitzt vor Ihren Subgraphen und übernimmt die Abfrageplanung, -ausführung und Antwortkomposition.
apollo-router-plugin-creator
apollographql
Erstelle native Rust-Plugins für Apollo Router.
apollo-server
apollographql
Vollständiger Leitfaden zum Erstellen von GraphQL-Servern mit Apollo Server 5.x in verschiedenen Frameworks. Behandelt Schema-Definition, Resolver, Kontext-Einrichtung und Fehlerbehandlung mit TypeScript-Unterstützung. Unterstützt Standalone-Modus für Prototyping sowie Integrationen mit Express, Fastify, Koa und serverlosen Umgebungen. Enthält Resolver-Muster, Authentifizierung/Autorisierung, Plugins, DataLoader zur N+1-Vermeidung und Techniken zur Leistungsoptimierung. Bietet Referenzdokumentation für Datenquellen, Fehler...
graphql-operations
apollographql
Leitfaden für Best Practices zum Schreiben effizienter, typsicherer GraphQL-Operationen und deren Organisation mit Fragmenten. Behandelt Queries, Mutationen, Subscriptions und Fragmente mit Namenskonventionen, Variablensyntax und Direktivenverwendung. Betont Kernprinzipien: nur benötigte Felder anfordern, alle Operationen benennen, Variablen statt hartcodierter Werte verwenden und ID-Felder für die Cache-Fähigkeit einfügen. Empfiehlt, Fragmente mit Komponenten zu kollokieren und @include-/@skip-Direktiven für bedingte Felder zu nutzen...
graphql-schema
apollographql
We need to translate the given English text into German. The text is a description of a guide for GraphQL schema design. We must preserve the name "graphql-schema" but it's not in the text, so we don't include it. We must not add any extra commentary, labels, etc. Just translate the text. The text: "Industry best practices guide for designing intuitive, performant, and maintainable GraphQL schemas. Covers core design principles including client-centric type organization, explicit nullability patterns, and backwards-compatible evolution strategies Provides reference documentation on types, naming conventions, cursor-based pagination, error modeling, and security considerations Includes practical patterns for interfaces, unions, input types, mutations, and ID strategies with code examples" Note: There is a missing period after "strategies" and before "Provides". We'll treat it as two sentences. Also "code examples" at the end. Translation to German: "Leitfaden für Branchen-Best Practices zur Gestaltung intuitiver, leistungsfähiger und wartbarer GraphQL-S
rover
apollographql
We need to translate the given English text into German, preserving the name "rover" and any technical terms. The text describes the Apollo Rover CLI. We must not add any extra commentary or labels. The translation should be accurate and natural in German. Let's break down the text: "Apollo Rover CLI for managing GraphQL schemas, federation, and local supergraph development. Publish, fetch, and validate subgraph schemas; compose federated supergraphs locally or via GraphOS Includes schema checking (pre-deploy validation), linting, and introspection from running servers rover dev command starts a local Router with automatic schema composition for development workflows Supports CI/CD patterns with check-before-publish validation and JSON output for scripting Requires..." We need to translate this into German. Keep "rover" as is. Also "GraphQL", "federation", "supergraph", "subgraph", "GraphOS", "Router", "CI/CD", "JSON" are technical terms that should remain in English or be commonly used in German tech contexts. Usually, these are kept as is