一键导入
rust
Rust coding conventions. Apply when writing, reviewing, or modifying Rust code. Covers error handling, types, ownership, testing, and anti-patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Rust coding conventions. Apply when writing, reviewing, or modifying Rust code. Covers error handling, types, ownership, testing, and anti-patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Use `mdvs search` for any content lookup in a markdown directory — semantic / hybrid / SQL-filtered, beats Grep / Glob for finding by meaning. `mdvs init` infers a schema from existing markdown, `mdvs check` validates frontmatter, `mdvs update` evolves the schema as the KB grows. Activate whenever the project contains markdown with frontmatter, whether or not `mdvs.toml` exists yet.
Release process for mdvs. Use when the user asks to make a release (patch, minor, major, or release candidate).
Use when the user asks to commit, commit and push, or make a git commit. Covers branching, commit workflow, conventional commits, TODO updates, and push/PR rules.
Use when writing, modifying, or removing Rust code in the mdvs codebase. Covers implementation workflow, testing, verification, and downstream updates (specs, example_kb, mdbook).
mdBook documentation conventions. Apply when writing, editing, or reviewing pages in book/src/. Covers content rules, example verification, tone, and structure.
GitHub Issues + Project tracking. Use when creating, updating, or querying issues and managing the project board.
| name | rust |
| description | Rust coding conventions. Apply when writing, reviewing, or modifying Rust code. Covers error handling, types, ownership, testing, and anti-patterns. |
Result<T, E> for fallible operationsthiserror with #[derive(Error)] for library error enums. Structure: variant name describes the failure, #[error("...")] format string includes diagnostic context (sizes, IDs), use #[from] for transparent wrapping of upstream errors? operator — avoid match chains for error forwarding.unwrap() or .expect() outside of testsanyhow for binary/CLI code where specific error types don't matter; never in library crates&T over .clone() unless ownership transfer is required&str over String, &[T] over Vec<T> in function parametersCopy types (<=24 bytes) can be passed by valueCow<'_, T> when ownership is ambiguous at compile time.clone() to satisfy the borrow checker, step back and reconsider the data flowpub struct UserId(pub Uuid), pub struct Port(pub u16)Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize — include only what's semantically correctCopy for small value types (IDs, enums). Clone but not Copy for larger typesDisplay manually when the type appears in logs or user-facing output/// doc comments on all public types, functions, and enum variants — explain what and how// inline comments only to explain why (safety invariants, workarounds, design rationale)// --- Section Name --- separatorsTODO needs a linked issue: // TODO(#42): description//! doc comments unless the module is a public API entry point#[cfg(test)] mod tests { } at the bottom of each modulesnake_case_description — be descriptive (e.g., buffer_duplicate_insert_ignored)#[tokio::test] for async tests — always with timeoutssleep.iter(), .map(), .filter()) over index-based loops.collect() — chain iterators directly.iter() for Copy types, .into_iter() when consuming ownershipcargo clippy after every change#[expect(clippy::lint_name)] over #[allow(...)] — expect warns if the lint no longer triggersredundant_clone, large_enum_variant (consider Box), needless_collect| Anti-Pattern | Why Bad | Better |
|---|---|---|
.clone() everywhere | Hides ownership issues | Proper references or restructure data flow |
.unwrap() in library code | Runtime panics | ?, or handle the error |
String in function params | Unnecessary allocation | &str, Cow<str> |
| Index-based loops | Error-prone, unidiomatic | Iterators |
Rc/Arc when single owner | Unnecessary overhead | Simple ownership |
| Giant match arms | Unmaintainable | Extract to methods |
Ignoring #[must_use] | Silently dropped errors | Handle or let _ = |
unsafe without SAFETY comment | UB risk, no audit trail | Document invariants or find safe pattern |