m04-zero-cost

Implement compile-time polymorphism in Rust using generics and static dispatch.

1|Updated May 29, 2026
One-click install
npx skills add https://github.com/simorgh3196/tsuzulint --skill m04-zero-cost
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: m04-zero-cost
Source: https://github.com/simorgh3196/tsuzulint/tree/main/.agents/skills/m04-zero-cost
Command: npx skills add https://github.com/simorgh3196/tsuzulint --skill m04-zero-cost

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill teaches how to implement zero-cost abstractions in Rust to achieve compile-time polymorphism with zero runtime overhead.

Core Features & Use Cases

  • Polymorphic without cost: Use generics with static dispatch to avoid vtables and dynamic dispatch overhead.
  • Monomorphization strategies: Understand how monomorphization affects inlining and code size for different type parameters.
  • Performance-conscious design: Make informed trade-offs between generics and trait objects in performance-critical paths.

Quick Start

Refactor a small Rust example to replace a trait object with a generic implementation and compare the performance and binary size.

Frequently Asked Questions about m04-zero-cost

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Rust generics for zero-cost abstractions instead of trait objects?▼

Rust generics provide zero-cost abstractions through compile-time monomorphization and static dispatch, eliminating the runtime vtable lookup overhead inherent in dynamic trait objects.

What is the difference between static and dynamic dispatch in Rust performance-critical code?▼

Static dispatch inlines generic calls at compile time with zero runtime overhead, whereas dynamic dispatch uses trait objects and vtable lookups that introduce a runtime performance penalty.

How does monomorphization affect Rust binary size and inlining?▼

Monomorphization generates specialized code for each generic type parameter at compile time, enabling aggressive inlining but potentially increasing final binary size due to code duplication.

When should I choose generics over trait objects for Rust polymorphism?▼

Choose generics for polymorphism in performance-critical paths to leverage static dispatch, and reserve trait objects for scenarios requiring dynamic sizing or heterogeneous collections.

Do I need external dependencies to implement static dispatch with impl Trait in Rust?▼

No, implementing static dispatch and zero-cost abstractions relies entirely on standard Rust tooling, generics, impl Trait, and trait bounds without requiring any external dependencies.