m04-zero-cost

Explain Rust zero-cost abstractions and resolve trait-related compiler errors.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill m04-zero-cost-mte90
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m04-zero-cost
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/m04-zero-cost
Command: npx skills add https://github.com/Mte90/dotfiles --skill m04-zero-cost-mte90

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers understand and correctly apply Rust's zero-cost abstractions, distinguishing between compile-time (generics) and runtime (trait objects) polymorphism to optimize performance and flexibility.

Core Features & Use Cases

  • Compile-time vs. Runtime Polymorphism: Guides decisions on when to use generics (static dispatch) versus trait objects (dynamic dispatch).
  • Error Resolution: Provides strategies for debugging common Rust type system errors like E0277, E0308, E0599, and E0038.
  • Use Case: When encountering a Rust compiler error related to trait bounds or type mismatches, this Skill offers a structured approach to analyze the abstraction level, type knowledge timing, and performance priorities to arrive at the correct solution.

Quick Start

Use the m04-zero-cost skill to understand the difference between static and dynamic dispatch in Rust.

Frequently Asked Questions about m04-zero-cost

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

FAQPage Schema
What is the difference between static and dynamic dispatch in Rust?

Static dispatch uses generics to resolve types at compile time for zero-cost abstractions, while dynamic dispatch uses trait objects to resolve types at runtime, trading slight performance for flexibility.

How do I fix Rust compiler error E0277 related to trait bounds?

To resolve Rust error E0277, analyze your abstraction level and ensure the trait bounds are satisfied. This Skill guides design decisions based on compile-time versus runtime type knowledge and performance needs.

When should I use Rust trait objects instead of generics?

Use Rust trait objects for dynamic dispatch when the exact type is unknown until runtime and flexibility outweighs performance. Use generics for static dispatch when types are known at compile time to achieve zero-cost abstractions.

Why does my Rust code fail with error E0038 on trait objects?

Rust error E0038 occurs when a trait violates object safety rules. This Skill covers object safety constraints and anti-patterns, guiding you to correctly apply dynamic dispatch without violating type system requirements.

How do I resolve Rust type mismatch error E0308 when implementing traits?

Resolve Rust error E0308 by evaluating compile-time versus runtime type knowledge. This Skill provides a structured approach to analyze abstraction levels and adjust type annotations or trait bounds to eliminate mismatches.