rust-api-guidelines
Idiomatic Rust API design, naming, traits, error handling, and type safety.
Skill by PierreZ
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/pierrez-rust-api-guidelines
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: design, backend, writing
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/rust-api-guidelines
Tools it pre-approves 4
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
Read,Grep,Edit,Write
What's inside
- Skill name
rust-api-guidelines- Description
- Idiomatic Rust API design, naming, traits, error handling, and type safety. Use when writing or reviewing Rust code, designing library APIs, or implementing traits and error types.
- License
- Apache-2.0
- Allowed tools
- Read,, Grep,, Edit,, Write
- Instructions
- 97 lines in SKILL.md · view on GitHub
Files (2)
- REFERENCE.md
- SKILL.md
SKILL.md (first lines)
# Rust API Guidelines
Apply these rules when writing or reviewing Rust code. See [REFERENCE.md](REFERENCE.md) for full details.
## Top LLM Violations
| # | Guideline | Wrong | Right |
|---|-----------|-------|-------|
| 1 | C-COMMON-TRAITS | No derives on public types | `#[derive(Debug, Clone, PartialEq)]` minimum |
| 2 | C-QUESTION-MARK | `.unwrap()` in lib/example code | `?` with `Result` return types |
| 3 | C-GENERIC | `fn f(v: &Vec<T>)`, `fn f(s: &String)` | `fn f(v: &[T])`, `fn f(s: &str)` |
| 4 | C-GETTER | `fn get_name(&self) -> &str` | `fn name(&self) -> &str` |
| 5 | C-GOOD-ERR | `Result<T, ()>`, `Result<T, String>` | Domain error enum with `thiserror` |
| 6 | C-CONV | Wrong conversion prefix | See Conversion Naming below |
| 7 | C-DEREF | `Deref` on wrapper types | Only for smart pointers (`Box`, `Arc`) |
| 8 | C-STRUCT-BOUNDS | `struct Foo<T: Debug + Clone>` | `struct Foo<T>` — bounds on `impl` only |
| 9 | C-CALLER-CONTROL | Hidden `.clone()`, wrong ownership | Take owned when you need it, borrow when you don't |
| 10 | C-STRUCT-PRIVATE | All `pub` fields on library structs | Private fields + `new()` + getters |
| 11 | C-FAILURE | No error docs | `# Errors`, `# Panics`, `# Safety` sections |
| 12 | C-BUILDER | Struct with 5+ pub config fields | Builder: `FooBuilder::new().bar(1).build()` |
| 13 | C-NEWTYPE | `user_id: u64`, `timeout: u64` | `struct UserId(u64)`, `struct Timeout(Duration)` |
| 14 | C-CUSTOM-TYPE | `fn connect(use_tls: bool)` | `enum TlsMode { Enabled, Disabled }` |
| 15 | C-NEWTYPE-HIDE | `-> Enumerate<Skip<Map<...>>>` | `-> impl Iterator<Item = T>` or newtype |
## Conversion Naming
| Prefix | Cost | Ownership | Example |
|--------|------|-----------|---------|
| `as_` | Free | `&self -> &T` | `fn as_str(&self) -> &str` |
| `to_` | Expensive | `&self -> T` (allocates) | `fn to_string(&self) -> String` |
| `into_` | Variable | `self -> T` (consumes) | `fn into_inner(self) -> T` |
| `from_` | Variable | `T -> Self` (constructs) | `fn from_bytes(v: Vec<u8>) -> Self` |
## Trait Checklist
| Type category | Always derive | When applicable |
|---------------|---------------|-----------------|
| Public structs | `Debug`, `Clone` | `Default`, `PartialEq`, `Eq`, `Hash` |
| Error types | `Debug` + manual `Display` + `Error` | `Clone`, must be `Send + Sync + 'static` |
| ID / newtype | `Debug`, `Clone`, `Copy`, `PartialEq`, `Eq`, `Hash` | `Display`, `Ord` |
| Config / options | `Debug`, `Clone`, `Default` | `PartialEq` |
| API boundary types | `Debug`, `Clone`, `PartialEq`, `Serialize`, `Deserialize` | `JsonSchema` |
## Generic Parameters
| Instead of | Accept | Why |
|------------|--------|-----|
| `&Vec<T>` | `&[T]` | Works with arrays, slices, Vec |
| `&String` | `&str` | Works with literals, String, Cow |
| `&Box<T>` | `&T` | Box is transparent for borrows |
| `String` param | `impl Into<String>` | Accepts `&str` without caller `.to_string()` |
| `PathBuf` param | `impl AsRef<Path>` | Accepts `&str`, `&Path`, `PathBuf` |
| `Vec<T>` param | `impl IntoIterator<Item = T>` | Accepts arrays, slices, iterators |
## Type Design
- **Newtype IDs**: `#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[serde(transparent)] pub struct JobId(pub Uuid);`
- **Enum state machines**: States as enum variants with embedded data. No struct-with-booleans/optionals.
- **Validated newtypes**: Private fields + `fn new(...) -> Result<Self, Error>` + custom `Deserialize` that calls `new`.
## Error Handling
- Define domain error enums with `#[derive(Debug, thiserror::Error)]`, specific variants with context fields.
- With `#[source]`, don't embed `{err}` in `#[error("...")]` — the error chain formatter appends it. Embedding causes double-printing.
## Functions
- Target 10-30 lines per function. Decompose longer functions into well-named helpers.
- Value composition and testability: each function does one thing, returns a value, is independently testable.
## Async / Tokio
**Apply only to applications already using tokio. Libraries must not embed a runtime.**
| Pattern | Rule |
|---------|------|
| Event loop | Single `select!` returning typed action enum, clean `loop { let action = select().await; apply(action).await; }` |
| Futurelock | Never hold locks across `select!` branches. Use channels + `spawn` instead. |
| Cancel-safety | `scopeguard::guard()` to restore invariants on drop. Defuse with `ScopeGuard::into_inner()` on success. |
| Channels | Bounded `mpsc` (backpressure), `oneshot` (request-reply), `watch` (broadcast/cancel). Avoid unbounded mpsc. |
| Lock scope | Clone data out of mutex before `.await`. Never hold `MutexGuard` across await points. |
## Clippy
- Never add `#[allow(clippy::...)]` to suppress a Clippy warning. Fix the underlying issue instead.
## Testing
- Write tests before implementation. Use `#[cfg(test)] mod tests` in the same file.
- Wrap external dependencies behind traits for testability. **Ask the developer** about the scope: IO boundaries only, all external deps, or full ports-and-adapters.
## Full Reference
- [Rust API Guidelines](https://rust-lang.github.io/api-guidelines) | [Checklist](https://rust-lang.github.io/api-guidelines/checklist.html)
- [REFERENCE.md](REFERENCE.md) — all 54 guidelines + pattern detailsFrom PierreZ/claude-personal-skills, Apache-2.0.
More from PierreZ/claude-personal-skills
- 0.497score
issue-to-branch
PierreZ
Read open issues from GitHub or GitLab, automatically choose the next logical one (or use a given issue number), spawn sub-agents to explore the code and plan…
SkillCFreshness: C★ 1Claude Code - 0.497score
sim-boundaries
PierreZ
Sim-driven testing — replace mocks and testcontainers with in-memory trait-based fakes at the right boundary.
SkillCFreshness: C★ 1Claude Code +9 - 0.429score
handover
PierreZ
Generate a HANDOVER.md shift-change report capturing the full session context — what was done, what worked, what didn't, decisions made, lessons learned, next…
SkillDFreshness: D★ 1Claude Code +9 - 0.414score
spec-interview
PierreZ
Interview me to create a detailed spec
SkillDFreshness: D★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Feb 25, 2026 (8 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from PierreZ
- 0.497score
issue-to-branch
PierreZ
Read open issues from GitHub or GitLab, automatically choose the next logical one (or use a given issue number), spawn sub-agents to explore the code and plan…
SkillCFreshness: C★ 1Claude Code - 0.497score
sim-boundaries
PierreZ
Sim-driven testing — replace mocks and testcontainers with in-memory trait-based fakes at the right boundary.
SkillCFreshness: C★ 1Claude Code +9 - 0.429score
handover
PierreZ
Generate a HANDOVER.md shift-change report capturing the full session context — what was done, what worked, what didn't, decisions made, lessons learned, next…
SkillDFreshness: D★ 1Claude Code +9 - 0.414score
spec-interview
PierreZ
Interview me to create a detailed spec
SkillDFreshness: D★ 1Claude Code +9
Cite this page
rust-api-guidelines skill. Agent Mart. https://agentmart.dev/skills/pierrez-rust-api-guidelines (last updated 2026-10-24)