Langsung ke konten
Skillpedia
API & server (backend)18k · #10707

rust-expert

Fungsinya

Skill ini memandu penulisan program Rust, termasuk kepemilikan dan peminjaman, penanganan galat, trait, serta kode async dengan Tokio. Skill ini untuk pengembang yang menginginkan perangkat lunak yang cepat dan aman dari sisi memori.

Kapan dipakai

  • ✓Saat Anda menulis atau meninjau kode Rust yang menangani kepemilikan atau lifetime.
  • ✓Saat Anda memerlukan tugas async konkuren dengan Tokio.
  • ✓Saat Anda ingin memodelkan galat dan state di Rust dengan tipe yang jelas.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Tulis fungsi Rust yang membaca berkas konfigurasi, mengembalikan galat yang jelas jika berkasnya hilang, dan memuat nilainya ke dalam struct.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini merekomendasikan tipe yang dimiliki di batas API, galat eksplisit berbasis Result, enum alih-alih flag, dan penggunaan unsafe seminimal mungkin dengan alasan yang didokumentasikan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Apa itu kepemilikan di Rust?

Itu adalah aturan bahwa setiap nilai memiliki satu pemilik, sehingga Rust dapat membebaskan memori dengan aman tanpa garbage collector.

Kapan saya boleh memakai kode unsafe?

Skill ini menyatakan hanya ketika pendekatan aman tidak bisa mengekspresikan operasi tersebut, dan setiap aturan keamanan harus didokumentasikan.

Crate galat apa yang disarankan?

Skill ini menyarankan thiserror untuk galat pustaka dan anyhow untuk penanganan galat tingkat aplikasi.

Detail

Deskripsi asli dari pembuat

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

repo: RightNow-AI/openfang

Popularitas

Bintang GitHub
18k
Peringkat
#10707
Lisensi
Apache-2.0
Diperbarui
2/7/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa