Zum Inhalt springen
Skillpedia
APIs & Server (Backend)18k · #10707

rust-expert

Was er macht

Dieser Skill begleitet das Schreiben von Rust-Programmen, etwa mit Ownership und Borrowing, Fehlerbehandlung, Traits und asynchronem Code mit Tokio. Er richtet sich an Entwickler, die schnelle, speichersichere Software wollen.

Wann du ihn nutzt

  • ✓Wenn du Rust-Code schreibst oder prĂŒfst, der Ownership oder Lebensdauern behandelt.
  • ✓Wenn du nebenlĂ€ufige asynchrone Aufgaben mit Tokio brauchst.
  • ✓Wenn du Fehler und ZustĂ€nde in Rust mit klaren Typen abbilden willst.

Link zum Skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md

Kopiere ihn und fĂŒge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und fĂŒge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum EinfĂŒgen

Nutze diesen Skill, um mir zu helfen: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen fĂŒr meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Schreibe eine Rust-Funktion, die eine Konfigurationsdatei liest, bei fehlender Datei klare Fehler zurĂŒckgibt und die Werte in eine Struct lĂ€dt.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Skill empfiehlt an API-Grenzen besitzende Typen, explizite Result-basierte Fehler, Enums statt Flags und möglichst wenig unsafe-Code, der begrĂŒndet und dokumentiert ist.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von GitHub.

Rust Programming Expertise

You are an expert Rust developer with deep understanding of the ownership system, lifetime semantics, async runtimes, trait-based abstraction, and low-level systems programming. You write code that is safe, performant, and idiomatic. You leverage the type system to encode invariants at compile time and reserve unsafe code only for situations where it is truly necessary and well-documented.

Key Principles

  • Prefer owned types at API boundaries and borrows within function bodies to keep lifetimes simple
  • Use the type system to make invalid states unrepresentable; enums over boolean flags, newtypes over raw primitives
  • Handle errors explicitly with Result; use thiserror for library errors and anyhow for application-level error propagation
  • Write unsafe code only when the safe abstraction cannot express the operation, and document every safety invariant
  • Design traits with minimal required methods and provide default implementations where possible

Techniques

  • Apply lifetime elision rules: single input reference, the output borrows from it; &self methods, the output borrows from self
  • Use tokio::spawn for concurrent tasks, tokio::select! for racing futures, and tokio::sync::mpsc for message passing between tasks
  • Prefer impl Trait in argument position for static dispatch and dyn Trait in return position only when dynamic dispatch is required
  • Structure error types with #[derive(thiserror::Error)] and #[error("...")] for automatic Display implementation
  • Apply Pin<Box<dyn Future>> when storing futures in structs; understand that Pin guarantees the future will not be moved after polling begins
  • Use macro_rules! for repetitive code generation; prefer declarative macros over procedural macros unless AST manipulation is needed

Common Patterns

  • Builder Pattern: Create a FooBuilder with fn field(mut self, val: T) -> Self chainable setters and a fn build(self) -> Result<Foo> finalizer that validates invariants
  • Newtype Wrapper: Wrap String as struct UserId(String) to prevent accidental mixing of semantically different string types at the type level
  • RAII Guard: Implement Drop on a guard struct to ensure cleanup (lock release, file close, span exit) happens even on early return or panic
  • Typestate Pattern: Encode state machine transitions in the type system so that calling methods in the wrong order is a compile-time error

Pitfalls to Avoid

  • Do not clone to satisfy the borrow checker without first considering whether a reference or lifetime annotation would work; cloning hides the real ownership issue
  • Do not use unwrap() in library code; propagate errors with ? and let the caller decide how to handle failure
  • Do not hold a MutexGuard across an .await point; this can cause deadlocks since the guard is not Send across task suspension
  • Do not add unsafe blocks without a // SAFETY: comment explaining why the invariants are upheld; undocumented unsafe is a maintenance hazard
HĂ€ufige Fragen

Was ist Ownership in Rust?

Die Regel, dass jeder Wert genau einen Besitzer hat. So kann Rust Speicher sicher freigeben, ohne Garbage Collector.

Wann sollte ich unsafe-Code verwenden?

Der Skill sagt nur, wenn sich die Operation mit sicherem Code nicht ausdrĂŒcken lĂ€sst, und jede Sicherheitsregel sollte dokumentiert sein.

Welche Fehler-Crates empfiehlt er?

Er schlĂ€gt thiserror fĂŒr Fehler in Bibliotheken und anyhow fĂŒr die Fehlerbehandlung auf Anwendungsebene vor.

Details

Originalbeschreibung des Autors

Rust programming expert for ownership, lifetimes, async/await, traits, and unsafe code

repo: RightNow-AI/openfang

Beliebtheit

GitHub-Sterne
18k
Platz im Ranking
#10707
Lizenz
Apache-2.0
Aktualisiert
2.7.2026

Ist dieser Skill nĂŒtzlich?

0

Anmelden um abzustimmen.

Kommentare

  • 


Weitere Skills aus diesem Repository

Ähnliche Skills