rust-expert
Skill này làm gì
Skill này hướng dẫn viết chương trình Rust, gồm quyền sở hữu và mượn (borrowing), xử lý lỗi, trait và mã bất đồng bộ với Tokio. Skill dành cho lập trình viên muốn phần mềm nhanh và an toàn về bộ nhớ.
Khi nào nên dùng
- ✓Khi bạn đang viết hoặc xem lại mã Rust có xử lý quyền sở hữu hoặc vòng đời.
- ✓Khi bạn cần chạy nhiều tác vụ bất đồng bộ đồng thời với Tokio.
- ✓Khi bạn muốn mô hình hóa lỗi và trạng thái trong Rust bằng các kiểu dữ liệu rõ ràng.
Liên kết skill
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy viết một hàm Rust đọc file cấu hình, trả về lỗi rõ ràng nếu file bị thiếu và nạp các giá trị vào một struct.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill khuyến nghị dùng kiểu sở hữu ở ranh giới API, lỗi dựa trên Result tường minh, enum thay cho cờ (flag) và hạn chế tối đa unsafe, kèm lý do được ghi chép rõ.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Quyền sở hữu trong Rust là gì?
Đó là quy tắc mỗi giá trị chỉ có một chủ sở hữu, nhờ đó Rust giải phóng bộ nhớ an toàn mà không cần garbage collector.
Khi nào nên dùng mã unsafe?
Skill nói chỉ khi không có cách an toàn nào diễn đạt được thao tác đó, và mọi quy tắc an toàn phải được ghi lại.
Skill gợi ý thư viện xử lý lỗi nào?
Skill gợi ý thiserror cho lỗi trong thư viện và anyhow cho xử lý lỗi ở mức ứng dụng.
Chi tiết
Mô tả gốc của tác giả
Rust programming expert for ownership, lifetimes, async/await, traits, and unsafe code
repo: RightNow-AI/openfang
Độ phổ biến
- Sao GitHub
- 18k
- Vị trí xếp hạng
- #10707
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/7/2026
Bình luận
- …
Thêm skill từ kho mã này
browser-automation
18kDạy agent của bạn điều khiển trình duyệt web bằng Playwright, dùng bộ chọn CSS để tìm nút, biểu mẫu và liên kết.
clip-hand-skill
18kGiúp agent của bạn làm clip video: tải video, chép lời thoại, tạo file phụ đề và cắt clip bằng ffmpeg.
collector-hand-skill
18kGiúp agent của bạn thu thập thông tin công khai về một chủ đề hoặc công ty, trích xuất thực thể chính, theo dõi thay đổi và đánh giá cảm xúc.
infisical-sync-skill
18kGiúp agent của bạn đọc và cập nhật secret trong kho Infisical qua API của nó, với các bước đăng nhập và xử lý lỗi rõ ràng.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.