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.
npx skills add actionbook/rust-skills --skill m04-zero-cost -a claude-codeWhat 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 Traitfor 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-code2Manually: put the files in place
~/.claude/skills/m04-zero-cost/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/m04-zero-cost/
1Skills CLI (Vercel)
npx skills add actionbook/rust-skills --skill m04-zero-cost -a codex2Manually: put the files in place
.agents/skills/m04-zero-cost/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add actionbook/rust-skills --skill m04-zero-cost -a cursor2Manually: put the files in place
.cursor/skills/m04-zero-cost/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install actionbook/rust-skills m04-zero-cost2Manually: put the files in place
.github/skills/m04-zero-cost/SKILL.md1Skills CLI (Vercel)
npx skills add actionbook/rust-skills --skill m04-zero-cost -a gemini-cli2Platform CLI
gemini skills install https://github.com/actionbook/rust-skills --path skills/m04-zero-costManually: put the files in place
.devin/skills/m04-zero-cost/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add actionbook/rust-skills --skill m04-zero-cost -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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.