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) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“اكتب دالة 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
thiserrorfor library errors andanyhowfor 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;
&selfmethods, the output borrows from self - Use
tokio::spawnfor concurrent tasks,tokio::select!for racing futures, andtokio::sync::mpscfor message passing between tasks - Prefer
impl Traitin argument position for static dispatch anddyn Traitin 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 thatPinguarantees 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
FooBuilderwithfn field(mut self, val: T) -> Selfchainable setters and afn build(self) -> Result<Foo>finalizer that validates invariants - Newtype Wrapper: Wrap
Stringasstruct UserId(String)to prevent accidental mixing of semantically different string types at the type level - RAII Guard: Implement
Dropon 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
MutexGuardacross an.awaitpoint; this can cause deadlocks since the guard is notSendacross task suspension - Do not add
unsafeblocks 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
التعليقات
- …
المزيد من المهارات من هذا المستودع
browser-automation
18kيعلّم وكيلك التحكم في متصفح الويب باستخدام Playwright، معتمدًا على محددات CSS للعثور على الأزرار والنماذج والروابط.
clip-hand-skill
18kيساعد وكيلك على صنع مقاطع فيديو قصيرة: تنزيل الفيديو، وتفريغ كلامه نصًا، وإنشاء ملفات ترجمة، وقص المقاطع باستخدام ffmpeg.
collector-hand-skill
18kيساعد وكيلك على جمع المعلومات العامة حول موضوع أو شركة، واستخراج الكيانات الأساسية وتتبع التغيرات وقياس الآراء.
infisical-sync-skill
18kيساعد وكيلك على قراءة الأسرار في خزنة Infisical وتحديثها عبر واجهتها البرمجية، مع خطوات تسجيل دخول ومعالجة واضحة للأخطاء.
مهارات مشابهة
api-connector-builder
280kيبني وكيلك اتصالات API جديدة على النمط الموجود، ويفيد عندما تحتاج إلى تكامل إضافي دون ابتكار طريقة جديدة للعمل.
api-design
280kيساعد وكيلك على تصميم واجهات REST API وفق أفضل الممارسات، ويوضح كيف تتواصل وكيف تُعرض الأخطاء وكيف تُنظَّم البيانات.
backend-patterns
280kيساعد وكيلك على أنماط بنية الخادم وتحسين قاعدة البيانات، ويفيد في بناء الشيفرة التي تعمل على الخادم أو مراجعتها.