Skip to main content
skill CX Codex

m04-zero-cost — Claude Code skill for Rust generics and traits

Walks through E0277, E0308 and E0599 and helps you pick between generics and dyn Trait. Useful when Rust trait bounds stop cooperating.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add actionbook/rust-skills --skill m04-zero-cost -a claude-code
Open on GitHub

What m04-zero-cost does

The skill turns a compiler error into a design question. Instead of telling you to add a trait bound, it asks whether the abstraction sits at the right level: same behavior across types means a trait, different behavior on one type means an enum, no abstraction means a concrete type. The error table covers E0277, E0308, E0599 and E0038.

From there it moves to dispatch. Type known at compile time points to generics or impl Trait; type resolved at runtime points to dyn Trait. You get a syntax comparison for argument and return positions, plus a cost table — generics carry zero runtime overhead but grow code size, while dyn pays a vtable lookup and an allocation for Box.

A section on object safety lists what keeps a trait usable behind dyn: no Self: Sized bound, no returning Self, no generic methods. Anti-patterns are covered too, including reaching for dyn when the type is already known. The skill points at sibling modules m05-type-driven, m09-domain, m10-performance and m07-concurrency. It is not meant to be invoked by hand — user-invocable: false — so it fires when the agent sees matching code or a compiler error.

What it helps with

  • decode E0277 and find where the trait bound went wrong
  • choose between generics and dyn Trait for a plugin architecture
  • hold mixed types in a Vec<Box<dyn Trait>>
  • check a trait for object safety before switching to dynamic dispatch
  • cut compile time by trimming monomorphization

Example prompts for the agent

  • I'm hitting E0277 on a trait bound, check whether the abstraction is right
  • plugin architecture in Rust: generics or dyn Trait?
  • this trait isn't object-safe, what should I change

How to install m04-zero-cost

1Skills CLI (Vercel)

npx skills add actionbook/rust-skills --skill m04-zero-cost -a claude-code

2Manually: put the files in place

~/.claude/skills/m04-zero-cost/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/m04-zero-cost/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about m04-zero-cost

How do I install m04-zero-cost in Claude?

Run npx skills add actionbook/rust-skills --skill m04-zero-cost -a claude-code. The skill lands in ~/.claude/skills/m04-zero-cost/SKILL.md.

What does m04-zero-cost do?

It helps you choose between static and dynamic dispatch in Rust and works through trait bound errors. Think of it as a reference for generics, impl Trait and dyn Trait.

Can I invoke this skill manually?

No — the frontmatter sets user-invocable: false. The agent pulls it in on its own when generics, traits or the matching compiler errors show up.

Similar skills

All skills for Programming languages →

From the same set33

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor