Rust idioms — ownership, borrowing, lifetimes, error handling, traits, and iterators. Auto-load when working with .rs files, Cargo.toml, or when the user mentions Rust, cargo, ownership, borrow checker, trait, lifetime, or async Rust.
설치
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
Rust idioms — ownership, borrowing, lifetimes, error handling, traits, and iterators. Auto-load when working with .rs files, Cargo.toml, or when the user mentions Rust, cargo, ownership, borrow checker, trait, lifetime, or async Rust.
Rust
Ownership in one paragraph
Every value has one owner. Passing by value moves; borrow with & (shared, many) or &mut (exclusive, one). Shared and mutable references cannot coexist. Most "fights with the borrow checker" are a design smell — the data model mixed ownership and sharing.
Borrowing rules of thumb
&T when you only read.
&mut T when you mutate in place.
T (by value) when you consume — builders, transforming constructors.
Return owned types unless the caller clearly benefits from a borrow tied to a parameter's lifetime.
Lifetimes
Start without annotations; add them when the compiler asks.
'static does not mean "lives forever" — it means "no non-static references inside". Prefer owned types over 'static juggling.
If a struct needs many lifetimes, consider owned data or Arc instead.
Error handling
Return Result<T, E>; use ? to propagate.
Library code: custom enum with thiserror.
Application code:anyhow::Error for ergonomics; add context with .with_context(|| "doing X").
Reserve panic! for invariant violations the caller cannot recover from.
Reserve unwrap/expect for truly unreachable cases; always prefer expect("why") over unwrap in production.
Doc comments
rustdoc — /// doc comment: one summary line first; cargo doc renders it as the item's headline.
Add # Examples, # Panics, or # Safety sections only when they apply, not as boilerplate.
/// Returns the order total, excluding cancelled line items.pubfntotal(&self) -> Decimal { ... }
Tooling
Imports/Auto-fix:cargo fix --allow-dirty (applies all auto-fixable rustc/Clippy lints — review the full diff before staging; not suitable as an unattended CI step)
Format:cargo fmt (set imports_granularity in rustfmt.toml for import grouping; cargo fmt --check in CI)
Lint:cargo clippy -- -D warnings
Test:cargo test (see Testing below)
Testing
#[cfg(test)] mod tests { ... } at the bottom of each file for unit tests.
Integration tests in tests/.
#[should_panic(expected = "...")] for panic paths.
Async
Pick one runtime (usually tokio) and stay there.
async fn in traits — async-trait or the stable equivalent.
Send + 'static bounds propagate; design for them from the start.
Do not block in async — spawn_blocking for CPU or sync IO.
Avoid
unsafe without a // SAFETY: comment explaining the invariant.
Reimplementing iterators imperatively.
String where &str would do for read-only input.
Deep trait hierarchies — traits compose, they do not inherit.