The m04-zero-cost skill helps Rust developers choose between static and dynamic polymorphism when working with generics and trait objects, addressing common type system errors like E0277 and E0599. It's designed for programmers struggling with trait bounds, monomorphization, and zero-cost abstraction decisions by reframing compiler errors as design questions about whether types should be known at compile time or runtime. The skill traces upward to domain design and downward to specific implementation patterns, helping developers avoid unnecessary trait objects and code bloat while maintaining flexibility.

skills.sh installs
789
GitHub stars
1.3K
last updated
Jul 14, 2026

Install

$ npx -y skills add zhanghandong/rust-skills --skill m04-zero-cost --agent claude-code

Installs into .claude/skills of the current project.

Files

Zero-Cost Abstraction

Layer 1: Language Mechanics

Core Question

Do we need compile-time or runtime polymorphism?

Before choosing between generics and trait objects:

  • Is the type known at compile time?
  • Is a heterogeneous collection needed?
  • What's the performance priority?

Error → Design Question

ErrorDon't Just SayAsk Instead
E0277"Add trait bound"Is this abstraction at the right level?
E0308"Fix the type"Should types be unified or distinct?
E0599"Import the trait"Is the trait the right abstraction?
E0038"Make object-safe"Do we really need dynamic dispatch?

Thinking Prompt

Before adding trait bounds:

  1. What abstraction is needed?

    • Same behavior, different types → trait
    • Different behavior, same type → enum
    • No abstraction needed → concrete type
  2. When is type known?

    • Compile time → generics (static dispatch)
    • Runtime → trait objects (dynamic dispatch)
  3. What's the trade-off priority?

    • Performance → generics
    • Compile time → trait objects
    • Flexibility → depends

Trace Up ↑

Sponsors

Details

Repository
github.com/zhanghandong/rust-skills
Category
Rust

More from zhanghandong/rust-skills

All 34

Recommended

More Rust
1zhanghandong avatarm05-type-drivenzhanghandong/rust-skillsm05 type driven786skills.sh installs
2zhanghandong avatarm13-domain-errorzhanghandong/rust-skillsm13 domain error738skills.sh installs
3zhanghandong avatardomain-clizhanghandong/rust-skillsdomain cli709skills.sh installs
4zhanghandong avatardomain-cloud-nativezhanghandong/rust-skillsdomain cloud native596skills.sh installs
5zhanghandong avatardomain-fintechzhanghandong/rust-skillsdomain fintech581skills.sh installs
6zhanghandong avatardomain-mlzhanghandong/rust-skillsdomain ml573skills.sh installs