Skip to content
Agentmart
Submit a tool

rust

Idiomatic programming style, patterns, and conventions for Rust development.

Skill by nrdxp

IndexedMIT★ 10
Write a review

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/nrdxp-rust

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.

We use your email only for this newsletter. Privacy

About

Idiomatic programming style, patterns, and conventions for Rust development. Trigger when: - Writing, refactoring, reviewing, or debugging Rust code. - Files matching the pattern **/*.rs (including Cargo.toml, Cargo.lock) are in the workspace or referenced. - Tasks involve: cargo build, cargo clippy, cargo test, cargo check, rustc. - Prompt contains keywords: rust, cargo, clippy, borrow checker, lifetime, struct, enum, impl, Option, Result, match, unwrap, unsafe.

Use cases: testing, writing, agent-building

No 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

What's inside

Skill name
rust
Description
Idiomatic programming style, patterns, and conventions for Rust development. Trigger when: - Writing, refactoring, reviewing, or debugging Rust code. - Files matching the pattern **/*.rs (including Cargo.toml, Cargo.lock) are in the workspace or referenced. - Tasks involve: cargo build, cargo clippy, cargo test, cargo check, rustc. - Prompt contains keywords: rust, cargo, clippy, borrow checker, lifetime, struct, enum, impl, Option, Result, match, unwrap, unsafe.
License
MIT
Instructions
266 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Rust Language Idioms

Work _with_ the language, not against it. Embrace ownership, the borrow checker, and the type system.

---

## Core Values

- **Safety:** Lean on the compiler's guarantees. Avoid `unsafe` unless absolutely necessary.
- **Memory Efficiency:** Zero-cost abstractions. Avoid unnecessary allocations.
- **Ergonomics:** APIs should be intuitive and hard to misuse.

---

## API Design

### Naming Conventions

| Prefix  | Semantics                    | Cost      | Example                       |
| :------ | :--------------------------- | :-------- | :---------------------------- |
| `as_`   | Borrowed view, no allocation | Cheap     | `as_ref()`, `as_slice()`      |
| `to_`   | Creates new owned value      | Expensive | `to_string()`, `to_vec()`     |
| `into_` | Consumes self, transforms    | Cheap     | `into_iter()`, `into_inner()` |

### Argument Flexibility

Accept generic bounds instead of concrete types:

```rust
// ❌ Inflexible
fn read_file(path: &PathBuf) -> Result<String>

// ✅ Accepts &str, String, PathBuf, &Path
fn read_file(path: impl AsRef<Path>) -> Result<String>
```

Common patterns:

- `impl AsRef<Path>` — for paths
- `impl AsRef<str>` — for string-like types
- `impl Into<String>` — when ownership is needed

### Constructors

- **Simple:** `T::new()` for basic instantiation
- **Configured:** `T::with_capacity(n)` for single-option variants
- **Complex:** Use the **Builder pattern** for 3+ optional fields

```rust
let config = ConfigBuilder::new()
    .port(8080)
    .timeout(Duration::from_secs(30))
    .build()?;
```

### Monomorphization Control

For widely-used generic functions, consider splitting:

```rust
// Public generic wrapper (thin)
pub fn process(path: impl AsRef<Path>) -> Result<()> {
    process_inner(path.as_ref())
}

// Private concrete implementation (bulk of logic)
fn process_inner(path: &Path) -> Result<()> {
    // ...
}
```

This reduces binary bloat and compile times.

---

## Error Handling

### The `?` Operator

Use `?` to propagate errors. It:

1. Unwraps `Ok(value)` or returns `Err(e)` early
2. Automatically converts via `From` trait

### Library vs. Application Errors

| Context          | Approach                  | Crate       |
| :--------------- | :------------------------ | :---------- |
| **Libraries**    | Custom enum error types   | `thiserror` |
| **Applications** | Boxed errors with context | `anyhow`    |

```rust
// Library: structured, matchable errors
#[derive(Debug, thiserror::Error)]
pub enum ParseError {
    #[error("invalid header at byte {0}")]
    InvalidHeader(usize),
    #[error("unexpected EOF")]
    UnexpectedEof,
}

// Application: rich context chains
fn main() -> anyhow::Result<()> {
    let config = load_config()
        .context("failed to load configuration")?;
    Ok(())
}
```

### Parse, Don't Validate

Encode invariants in the type system:

```rust
// ❌ Stringly-typed, requires repeated validation
fn send_email(to: &str) -> Result<()>

// ✅ Invalid states are unrepresentable
fn send_email(to: EmailAddress) -> Result<()>

From nrdxp/predicate, MIT.

More from nrdxp/predicate

Signals

Stars
10
Forks
2
Open issues
1
Last commit (this folder)
Jun 20, 2026 (4 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from nrdxp

Cite this page

rust skill. Agent Mart. https://agentmart.dev/skills/nrdxp-rust (last updated 2026-10-24)