Rust Zero Cost
零成本抽象与泛型专家。处理泛型, trait, monomorphization, static dispatch, dynamic dispatch, impl Trait, dyn Trait, 泛型, 特征, 单态化, 零成本抽象--- # 零成本抽象与泛型 ## 核心问题 需要编译时多态还是运行时多态? 选择正确的抽象层次直接影响性能。
Install
npx skills add huiali/rust-skills --skill rust-zero-costgit clone --depth 1 https://github.com/huiali/rust-skills.git /tmp/rust-skills
mkdir -p ~/.claude/skills
cp -r /tmp/rust-skills/.codex/skills/rust-zero-cost ~/.claude/skills/rust-zero-costPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
## 泛型 vs Trait Object
| 特性 | 泛型 (static dispatch) | trait object (dynamic dispatch) |
|-----|----------------------|--------------------------------|
| 性能 | 零开销 | vtable 查找 |
| 代码大小 | 可能膨胀 | 更小 |
| 编译时间 | 更长 | 更短 |
| 灵活性 | 类型必须已知 | 运行时决定 |
| 异构集合 | 不支持 | `Vec<Box<dyn Trait>>` |
## 何时用泛型
```rust
// 类型在编译时已知
fn process<T: Processor>(item: T) {
item.process();
}
// 返回同一类型
fn create_processor() -> impl Processor {
// 返回具体类型
}
// 多个类型参数
fn combine<A: Display, B: Display>(a: A, b: B) -> String {
format!("{} and {}", a, b)
}
```
## 何时用 trait object
```rust
// 运行时决定类型
trait Plugin {
fn run(&self);
}
struct PluginManager {
plugins: Vec<Box<dyn Plugin>>,
}
// 异构集合
let handlers: Vec<Box<dyn Handler>> = vec![
Box::new(HttpHandler),
Box::new(GrpcHandler),
];
```
## 对象安全规则
```rust
// ❌ 不是对象安全的
trait Bad {
fn create(&self) -> Self; // 返回 Self
fn method(&self, x: Self); // 参数有 Self
}
// ✅ 对象安全
trait Good {
fn name(&self) -> &str;
}
```
## impl Trait vs dyn Trait
```rust
// impl Trait:返回具体类型(静态分发)
fn create_processor() -> impl Processor {
HttpProcessor
}
// dyn Trait:返回 trait object(动态分发)
fn create_processor() -> Box<dyn Processor> {
Box::new(HttpProcessor)
}
```
## 性能影响
```rust
// 泛型:每个类型生成一份代码
fn process<T: Trait>(item: T) {
item.method();
}
// 编译后:
// fn process_Http(item: Http) { ... }
// fn process_Ftp(item: Ftp) { ... }
// trait object:单一路径
fn process(item: &dyn Trait) {
item.method(); // 通过 vtable 调用
}
```Details
- Skill name
rust-zero-cost- Repository
- huiali/rust-skills
- Path
.codex/skills/rust-zero-cost/SKILL.md- License
- MIT
- Repo updated
- 9 February 2026
FAQ
What does the Rust Zero Cost skill do?
零成本抽象与泛型专家。处理泛型, trait, monomorphization, static dispatch, dynamic dispatch, impl Trait, dyn Trait, 泛型, 特征, 单态化, 零成本抽象--- # 零成本抽象与泛型 ## 核心问题 **需要编译时多态还是运行时多态?** 选择正确的抽象层次直接影响性能。
How do I install the Rust Zero Cost skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add huiali/rust-skills --skill rust-zero-cost. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Rust Zero Cost popular?
It lives in huiali/rust-skills, which has 49 GitHub stars and 7 forks.
Related skills
Rust Actor
49huiali/rust-skills
Actor model expert covering message passing, state isolation, supervision trees, deadlock prevention, fault tolerance, Actix framework, and Erlang-style concurrency patterns.
Rust Anti Pattern
49huiali/rust-skills
Rust anti-patterns and common mistakes expert. Handles code review issues with clone abuse, unwrap in production, String misuse, index loops, and refactoring guidance.
Rust Async
49huiali/rust-skills
Advanced async patterns expert. Handles Stream processing, backpressure control, select/join operations, cancellation, Future trait implementation, and async runtime optimization.
Tauri
48martinholovsky/claude-skills-generator
Cross-platform desktop application framework combining Rust backend with web frontend, emphasizing security and performance
Rust Xacml
49huiali/rust-skills
策略引擎、权限决策、RBAC、策略模式、责任链--- # Rust XACML - 策略引擎技能 > 本技能提供策略决策引擎的通用解决方案,包括 RBAC、责任链、策略模式等。 ## 核心概念 ### 1. 策略引擎架构 ``` 策略决策流程 ┌─────────────────────────────────────────────────────────────┐ │ 请求上下文 │ │ (主体、资源、操作、环境) │ └────────────────────────┬────────────────────────────────────┘ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 策略决策点 (PDP) │ │ ├── 策略加载 │ │ ├── 策略评估 │ │ └── 决策组合 │ └────────────────────────┬────────────────────────────────────┘ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 决策结果 │ │ (Permit / Deny / NotApplicable / Indeterminate) │ └─────────
Typescript
48martinholovsky/claude-skills-generator
Type-safe development patterns for JARVIS AI Assistant
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.