m04-zero-cost

Installation
Summary

Compile-time versus runtime polymorphism: generics, trait objects, and zero-cost abstraction patterns.

  • Distinguishes static dispatch (generics, impl Trait) from dynamic dispatch (dyn Trait), with decision guidance on when each is appropriate based on type knowledge, performance priorities, and collection heterogeneity
  • Maps common type system errors (E0277, E0308, E0599, E0038) to underlying design questions rather than mechanical fixes
  • Covers object safety constraints, monomorphization trade-offs, and anti-patterns like over-generics or unnecessary dyn indirection
  • Includes syntax reference, quick decision table, and trace-up/trace-down patterns linking to related domain and type-driven design skills
SKILL.md

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

Error Don't Just Say Ask Instead
Related skills

More from zhanghandong/rust-skills

Installs
716
GitHub Stars
1.1K
First Seen
Jan 20, 2026