跳到技能内容
词映 AI导航
发现工具选型指南Skills 技能AI 快讯AI图片AI视频AI文档AI办公AI助手AI搜索AI编程AI音频AI设计AI智能体模型与开发AI学习模型评测AI提示词内容检测AI金融AI 3D扫描与识别其他工具跨境电商 AI
词映 AI导航
工具库Skills 技能
我的收藏
词映 AI导航
发现工具选型指南Skills 技能AI 快讯AI图片AI视频AI文档AI办公AI助手AI搜索AI编程AI音频AI设计AI智能体模型与开发AI学习模型评测AI提示词内容检测AI金融AI 3D扫描与识别其他工具跨境电商 AI
Skills directory/huiali/rust-skills/rust-zero-cost

Codex Choose Rust Generics or dyn Trait for Formatter Dispatch

Compare static and dynamic dispatch with a compilable example and decide when heterogeneous collections are needed.

中文

Install in Codex

Use a local Rust project, Cargo, and the target trait and implementations.

  1. Copy the pinned `.codex/skills/rust-zero-cost/` directory into `.agents/skills/rust-zero-cost/` in the project.
  2. Tell Codex whether the concrete type is known at compile time and check that the trait supports `dyn`.

Example task

Define `LabelFormatter` with uppercase and identity implementations. Call a generic function with a known type and store both implementations in `Vec<Box<dyn LabelFormatter>>`.

What to check

The heterogeneous list dispatches to the two implementations correctly, and tests preserve the static call's output.

Original SKILL.md on GitHub · Updated 2026-11-13

Frequently asked question

Are generics always faster?

Measure the actual path, including allocations and code size, before making a performance claim.

Related skills from this repository

  • Codex Rust Const Generics for Fixed-Size Buffers
  • Codex Model Missing Values and Parse Failures in Rust
Browse Codex skills in the Chinese directory
词映 AI 导航Skills 技能
工具分类全部工具已本地化技能选型指南AI 快讯