rust-best-practices

We need to translate the given English text into German, preserving the name "rust-best-practices" if it appears. The text is a description of an agent skill. The instruction says: "Do not include the name unless it appears in the source text." The name "rust-best-practices" does not appear in the provided <text> block. So we should not add it. Also, preserve product names, protocol names, URLs, numbers, technical terms. So "Apollo GraphQL", "clippy", "thiserror", "anyhow", "Result", etc. should remain as is or translated? Technical terms like "clippy linting" might be kept as "Clippy-Linting" or similar. But the instruction says "preserve product names, protocol names, URLs, numbers, and technical terms." So we keep them in original form. However, we are translating to German, so we need to produce a natural German translation. For example, "Idiomatic Rust coding standards" -> "Idiomatische Rust-Codierungsstand

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

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

  • Prefer &T over .clone() unless ownership transfer is required
  • Use &str over String, &[T] over Vec<T> in function parameters
  • Small Copy types (≤24 bytes) can be passed by value
  • Use Cow<'_, T> when ownership is ambiguous

Error Handling

  • Return Result<T, E> for fallible operations; avoid panic! in production
  • Never use unwrap()/expect() outside tests
  • Use thiserror for library errors, anyhow for binaries only
  • Prefer ? operator over match chains for error propagation

Performance

  • Always benchmark with --release flag
  • Run cargo clippy -- -D clippy::perf for performance hints
  • Avoid cloning in loops; use .iter() instead of .into_iter() for Copy types
  • Prefer iterators over manual loops; avoid intermediate .collect() calls

Linting

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

Key lints to watch:

  • redundant_clone - unnecessary cloning
  • large_enum_variant - oversized variants (consider boxing)
  • needless_collect - premature collection

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

Testing

  • Name tests descriptively: process_should_return_error_when_input_empty()
  • One assertion per test when possible
  • Use doc tests (///) for public API examples
  • Consider cargo insta for snapshot testing generated output

Generics & Dispatch

  • Prefer generics (static dispatch) for performance-critical code
  • Use dyn Trait only when heterogeneous collections are needed
  • Box at API boundaries, not internally

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

  • // comments explain why (safety, workarounds, design rationale)
  • /// doc comments explain what and how for public APIs
  • Every TODO needs a linked issue: // TODO(#42): ...
  • Enable #![deny(missing_docs)] for libraries

Mehr Skills von apollographql

apollo-client
apollographql
Apollo Client ist eine umfassende Zustandsverwaltungsbibliothek für JavaScript, die es Ihnen ermöglicht, sowohl lokale als auch entfernte Daten mit GraphQL zu verwalten. Version 4.x bietet verbessertes Caching, bessere TypeScript-Unterstützung und Kompatibilität mit React 19.
official
apollo-client
apollographql
Umfassender Leitfaden zum Erstellen von React-Anwendungen mit Apollo Client 4.x, der Abfragen, Mutationen, Caching und Zustandsverwaltung abdeckt. Unterstützt mehrere React-Frameworks und -Setups: clientseitige Apps (Vite, CRA), Next.js App Router mit React Server Components, React Router 7 mit Streaming SSR und TanStack Start. Enthält Hooks für Abfragen (useQuery, useLazyQuery), Mutationen (useMutation) und Suspense-basierte Muster (useSuspenseQuery, useBackgroundQuery) für modernes React 18+ und 19...
official
apollo-connectors
apollographql
Integrieren Sie REST-APIs in GraphQL-Supergraphen mithilfe der @source- und @connect-Direktiven. Bietet einen strukturierten 5-Schritte-Prozess: API-Struktur analysieren, Schema mit Direktiven implementieren, via rover supergraph compose validieren, Connectors ausführen und Abdeckung testen. Unterstützt Anfragekonfiguration einschließlich Headern, Body-Payloads, Batching für N+1-Muster und Umgebungsvariablen-Injektion via $env. Behandelt Antwort-Mapping mit Feldauswahl, Aliasing, Unterauswahlen für verschachtelte Daten und Entitäten...
official
apollo-federation
apollographql
Apollo Federation ermöglicht das Zusammenführen mehrerer GraphQL-APIs (Subgraphen) zu einem einheitlichen Supergraphen.
official
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.
official
apollo-kotlin
apollographql
Apollo Kotlin ist ein stark typisierter GraphQL-Client, der aus Ihren GraphQL-Operationen und Ihrem Schema Kotlin-Modelle generiert, die in Android-, JVM- und Kotlin-Multiplatform-Projekten verwendet werden können.
official
apollo-mcp-server
apollographql
Verbinde KI-Agenten über das Model Context Protocol mit GraphQL-APIs, inklusive integrierter Introspections- und Operationstools. Stellt GraphQL-Operationen als MCP-Tools bereit; unterstützt drei Operationsquellen: lokale Dateien, GraphOS Studio-Sammlungen und persistierte Query-Manifeste. Bietet vier Introspection-Tools (introspect, search, validate, execute) zur Schemaerkundung und Ad-hoc-Query-Tests; der Minifizierungsmodus reduziert Token-Nutzung durch kompakte Notation. Konfigurierbare Authentifizierung über statische Header,...
official
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.
official