본문으로 건너뛰기
Skillpedia
API 및 서버 (백엔드)18k · #10707

rust-expert

하는 일

이 스킬은 소유권과 빌림, 오류 처리, 트레이트, Tokio를 쓴 비동기 코드를 포함해 Rust 프로그램을 작성하는 방법을 안내합니다. 빠르고 메모리 안전한 소프트웨어를 원하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓소유권이나 수명을 다루는 Rust 코드를 작성하거나 검토할 때.
  • ✓Tokio로 동시에 실행되는 비동기 작업이 필요할 때.
  • ✓명확한 타입으로 Rust에서 오류와 상태를 모델링하고 싶을 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“설정 파일을 읽고, 파일이 없으면 명확한 오류를 반환하며, 값을 구조체에 불러오는 Rust 함수를 작성해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 API 경계에서 소유 타입을 쓰고, 명시적인 Result 기반 오류를 쓰며, 플래그보다 열거형을 쓰고, 이유를 문서화한 채 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
업데이트
2026. 7. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬