Skillpedia
واجهات API والخوادم (backend)18k · #10707

rust-expert

ما الذي تفعله

تُرشد هذه المهارة كتابة برامج Rust، بما في ذلك الملكية والاستعارة ومعالجة الأخطاء والسمات والكود غير المتزامن باستخدام Tokio. وهي لمطوري البرمجيات الذين يريدون برمجيات سريعة وآمنة للذاكرة.

متى تستخدمها

  • ✓عندما تكتب كود Rust أو تراجعه يتعامل مع الملكية أو الأعمار.
  • ✓عندما تحتاج إلى مهام غير متزامنة متوازية باستخدام Tokio.
  • ✓عندما تريد نمذجة الأخطاء والحالات في Rust بأنواع واضحة.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“اكتب دالة Rust تقرأ ملف إعدادات، وتعيد أخطاء واضحة إذا كان مفقودًا، وتحمّل القيم في struct.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

توصي المهارة بأنواع مملوكة عند حدود الواجهات، وأخطاء صريحة قائمة على Result، وتفضيل enum على الأعلام، واستخدام unsafe بأقل قدر مع توثيق الأسباب.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من 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
الأسئلة الشائعة

ما الملكية في Rust؟

هي القاعدة التي تقول إن لكل قيمة مالكًا واحدًا، مما يسمح لـ Rust بتحرير الذاكرة بأمان دون جامع مهملات.

متى أستخدم كود unsafe؟

تقول المهارة فقط عندما لا يستطيع النهج الآمن التعبير عن العملية، ويجب توثيق كل قاعدة أمان.

أي مكتبات للأخطاء تقترح؟

تقترح thiserror لأخطاء المكتبات وanyhow لمعالجة الأخطاء على مستوى التطبيق.

التفاصيل

الوصف الأصلي من المؤلف

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

repo: RightNow-AI/openfang

الشعبية

نجوم GitHub
18k
الترتيب
#10707
الترخيص
Apache-2.0
آخر تحديث
2‏/7‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة