# m04-zero-cost

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

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3400 installs · ★ 1545
- Author: actionbook
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m04-zero-cost/SKILL.md
- Updated: 2026-08-23
- HTML: https://affpapa.org/en/nevibecode/skills/m04-zero-cost

## What it 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.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m04-zero-cost -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/m04-zero-cost/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/m04-zero-cost/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m04-zero-cost -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/m04-zero-cost/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m04-zero-cost -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/m04-zero-cost/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install actionbook/rust-skills m04-zero-cost
```

2. **Manually: put the files in place**
- File: `.github/skills/m04-zero-cost/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m04-zero-cost -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/actionbook/rust-skills --path skills/m04-zero-cost
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/m04-zero-cost/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m04-zero-cost -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m04-zero-cost/SKILL.md

## When to use it
- 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
- 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

## Similar
- [typescript](https://affpapa.org/en/nevibecode/skills/gentleman-programming-typescript.md) — skill · 496 installs
- [zig-comptime](https://affpapa.org/en/nevibecode/skills/zig-comptime.md) — skill · 443 installs
- [typescript-advanced-types](https://affpapa.org/en/nevibecode/skills/typescript-advanced-types.md) — skill · 92169 installs
- [golang-data-structures](https://affpapa.org/en/nevibecode/skills/golang-data-structures.md) — skill · 40300 installs
- [golang-samber-lo](https://affpapa.org/en/nevibecode/skills/golang-samber-lo.md) — skill · 38500 installs
- [typescript-pro](https://affpapa.org/en/nevibecode/skills/httpsgithubcomjeffallan-typescript-pro.md) — skill · 14200 installs

From the same set: [actionbook/rust-skills](https://affpapa.org/en/nevibecode/by/actionbook/rust-skills.md) — 35 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
