refactor_idiomatic_rust

refactor_idiomatic_rust is a skill for Claude Code, Codex from EmilLindfors/a2a-rs. It costs 85 tokens per session (878 once invoked), scanned A, original, MIT.

A guide for making Rust code follow common language patterns and use clearer APIs. It covers choices such as generics versus trait objects, enum dispatch, iterator use, conversion traits, and error handling.

In plain words
What is it for?
Use it when refactoring Rust functions or APIs, choosing between static and dynamic dispatch, designing traits, improving conversions, or simplifying iterator and error-handling code.
Why use it?
It helps remove awkward or overly complex Rust code while balancing performance, flexibility, readability, and clean error propagation.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: installed under .agents/ (shared by several agents).

Good fit Use it when refactoring Rust functions or APIs, choosing between static and…

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/emillindfors/a2a-rs/refactor_idiomatic_rust
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add EmilLindfors/a2a-rs --skill refactor_idiomatic_rust
Clone the repo
git clone --depth 1 https://github.com/EmilLindfors/a2a-rs

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor_idiomatic_rust

README.md
[![agentmods](https://agentmods.dev/badge/skills/emillindfors/a2a-rs/refactor_idiomatic_rust.svg)](https://agentmods.dev/skills/emillindfors/a2a-rs/refactor_idiomatic_rust)
Your own site
<a href="https://agentmods.dev/skills/emillindfors/a2a-rs/refactor_idiomatic_rust"><img src="https://agentmods.dev/badge/skills/emillindfors/a2a-rs/refactor_idiomatic_rust.svg" alt="Measured on agentmods" height="20"></a>
Per session 85 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 878 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00085 $0.00878
Opus 5 $0.00043 $0.00439
Sonnet 5 $0.00017 $0.00176
Haiku 4.5 $0.00009 $0.00088

Measured 7d ago against content hash cbe6b699b485, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

refactor_idiomatic_rust scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/plugins/rust-patterns/skills/refactor_idiomatic_rust/SKILL.md · 42 lines

How it starts

The opening of the file, as written. The whole thing — 42 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactor Idiomatic Rust

This skill helps you refactor Rust code into idiomatic patterns based on the "Rust Patterns & Engineering How-Tos" guide. When asked to refactor or review Rust code for idiomatic usage, apply the principles derived from: https://microsoft.github.io/RustTraining/rust-patterns-book/

Generics and Monomorphization

  • Prefer Generics (Static Dispatch) when dealing with a closed set of types or when performance in hot loops is critical (e.g., millions of calls). Generics are zero-cost abstractions as they inline perfectly, but be mindful of code bloat.
  • Prefer Trait Objects (dyn Trait Dynamic Dispatch) for cold paths, heterogeneous collections, plugin systems, or when the cost of monomorphization code bloat outweighs the minor cost of vtable lookup.
  • Use const fn where possible for simple constructors or logic that can be evaluated at compile time, reducing runtime overhead.

Traits and Composition

  • Distinguish between Associated Types (when there is one output/result per implementing type, e.g., Iterator::Item) and Generic Parameters (when a type can implement the trait for many target types, e.g., From<T>).
  • Consider using Enum Dispatch as a middle ground between Generics and dyn Trait. If the set of types is closed, placing them in an enum and implementing the trait on the enum gives static dispatch performance with dynamic-like flexibility without heap allocation or vtable cost.
  • Apply the Extension Trait pattern to safely add methods to foreign types (types you don't own). Define a trait with your method and provide a blanket implementation (impl<T: SomeBound> MyExtension for T).
  • Use Blanket Implementations carefully but effectively (e.g. impl<T: Display> ToString for T) to give trait implementations for free to any type matching the constraints.
  • Maintain Trait Object Safety Rules: Traits meant for dynamic dispatch must not have Self: Sized bounds on methods meant for the vtable, no generic type parameters on methods, and no Self in return position (unless boxed).

Read the full file on GitHub · 42 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 42 lines · 85 tokens per session scan A cbe6b699b485

Subscribe to this mod's changes

refactor_idiomatic_rust is a skill published in the GitHub repository EmilLindfors/a2a-rs (87 stars, last pushed yesterday), licensed MIT. It adds 85 tokens to every session and 878 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.