Skip to content
Back to skills

Rust Style Rules

ASecurity

Standing rules for Rust an assistant writes, covering ownership-first APIs, Result over panic, clippy-clean code, typed errors, async hygiene and minimal, justified unsafe.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 26, 2026
ai-agentsrustgoapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill rust-style-rules --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust Style Rules?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust Style Rules
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-rust-style-rules/badge)](https://www.skillsdirectory.com/skills/hermes-hq-rust-style-rules)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rust-style-rules
description: Standing rules for Rust an assistant writes, covering ownership-first APIs, Result over panic, clippy-clean code, typed errors, async hygiene and minimal, justified unsafe.
license: CC0-1.0
metadata:
  version: 1.0.0
  kind: rule
  category: conventions
  source: https://hermes-ide.com/prompts/rust-style-rules
  catalog: 2026.1014.1
---

# Rust style rules

Apply these rules to files matching: `**/*.rs`.

When you write or change Rust code in this project:

**Tooling**
- Code must pass `cargo fmt` and `cargo clippy --all-targets` with no warnings under the project's lint settings.
- Never silence a lint crate-wide. Allow a specific lint on the narrowest item, with a comment explaining why.
- Use the edition and minimum Rust version in `Cargo.toml`. Add a dependency only when it earns its place, with the fewest features needed.

**Ownership and APIs**
- Borrow in parameters when the function does not keep the value: `&str`, `&[T]`, `&Path` or `impl AsRef<Path>`. Take ownership (`String`, `Vec<T>`) when the value is stored.
- Do not add `.clone()` just to satisfy the borrow checker. Restructure the code first, and when a clone is the right answer, make it visible and cheap or explain it.
- Return owned values or iterators rather than references tied to temporary state. Use `Cow` when a value is only sometimes owned.
- Model states with enums rather than booleans or sentinel values, and wrap ids and units in newtypes.
- Implement standard traits (`From`, `TryFrom`, `Display`, `Default`, `Debug`) instead of ad hoc conversion methods, and mark results that must not be ignored with `#[must_use]`.

**Errors**
- Return `Result` for anything that can fail at runtime, and propagate with `?`.
- Do not call `unwrap()` in library or request-handling code. Use `expect("reason this cannot fail")` only for real invariants.
- Follow the project's error approach. Where there is none, use typed error enums (for example with `thiserror`) in libraries and contextual errors (for example `anyhow` with `.context(...)`) in binaries.
- Never panic across an FFI boundary or in a `Drop` implementation.

**Unsafe**
- Avoid `unsafe`. If it is necessary, keep the block as small as possible, put a `// SAFETY:` comment on it that states the invariants that make it sound, and wrap it in a safe API.
- Document every `unsafe fn` with a `# Safety` section, and test unsafe code under Miri where the project supports it.

**Concurrency and async**
- Prefer message passing or owned data over shared mutable state. When state is shared, use `Arc` with a `Mutex` or `RwLock` and keep critical sections short.
- Never hold a `std::sync::Mutex` guard across `.await`. Use the runtime's async mutex or restructure.
- Never block inside async code. Move blocking or CPU-heavy work to `spawn_blocking` or a dedicated thread.

**Style**
- Prefer iterator chains to index loops when they read clearly, and avoid collecting into a `Vec` only to iterate it again.
- Keep items private by default, and use `pub(crate)` before `pub`.
- Document public items with `///` comments, with an example for non-trivial APIs.
- Put unit tests in a `#[cfg(test)] mod tests` beside the code, and integration tests in `tests/`.

Files in this skill

  • SKILL.md3.2 KB
  • agents/openai.yaml281 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.