一键导入
rust-skill
Rust 编程专家技能。处理所有 Rust 相关问题:编译错误、所有权、生命周期、并发、async/await、性能优化等。触发词:Rust, cargo, 编译错误, ownership, borrow, lifetime, async, tokio, Send, Sync, Result, Error
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Rust 编程专家技能。处理所有 Rust 相关问题:编译错误、所有权、生命周期、并发、async/await、性能优化等。触发词:Rust, cargo, 编译错误, ownership, borrow, lifetime, async, tokio, Send, Sync, Result, Error
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | rust-skill |
| description | Rust 编程专家技能。处理所有 Rust 相关问题:编译错误、所有权、生命周期、并发、async/await、性能优化等。触发词:Rust, cargo, 编译错误, ownership, borrow, lifetime, async, tokio, Send, Sync, Result, Error--- |
问题:值被移动后继续使用
思路:
1. 真的需要所有权吗?→ 用引用 &T
2. 需要共享吗?→ 用 Arc<T>
3. 需要副本吗?→ clone() 或 Copy trait
建议:先问"为什么需要移动",通常借用就能解决问题
问题:生命周期注解缺失或不匹配
思路:
1. 返回引用时:生命周期来自哪个输入?
2. 结构体含引用:生命周期参数叫什么?
3. 能不能返回 owned 类型避免生命周期?
建议:生命周期注解是文档。好的注解能让读者一眼就知道关系
问题:类型不能跨线程发送或共享
思路:
1. Send:所有字段都 Send 吗?
2. Sync:内部可变性类型是否线程安全?
3. Rc 用了?→ 换成 Arc
建议:大多数原生类型自动满足。问题通常出在 Cell、Rc、raw pointer
? 而不是 unwrap()// 好的错误处理
fn load_config(path: &Path) -> Result<Config, ConfigError> {
let content = std::fs::read_to_string(path)
.map_err(|e| ConfigError::Io(e))?;
toml::from_str(&content)
.map_err(ConfigError::Parse)
}
// 好的所有权使用
fn process_items(items: &[Item]) -> Vec<Result<Item, Error>> {
items.iter().map(validate_item).collect()
}
// 好的并发代码
async fn fetch_all(urls: &[Url]) -> Vec<Response> {
let futures: Vec<_> = urls.iter()
.map(|u| reqwest::get(u))
.collect();
futures::future::join_all(futures).await
}
当你描述问题时,我会思考:
这个问题是语言层面的还是设计层面的?
最佳方案还是最简单方案?
有领域约束吗?
# 检查但不编译(快)
cargo check
# 运行测试
cargo test
# 代码格式化
cargo fmt
# 代码检查
cargo clippy
# 发布构建
cargo build --release
unwrap()rust-testing: unit, integration, property, and concurrency testing with proptest/loom/criterion.rust-database: SQLx/Diesel/SeaORM patterns, transaction boundaries, migrations, and query performance.rust-observability: tracing, metrics, OpenTelemetry instrumentation, and production diagnostics.rust-testing.rust-database.rust-observability.Actor model expert covering message passing, state isolation, supervision trees, deadlock prevention, fault tolerance, Actix framework, and Erlang-style concurrency patterns.
Rust anti-patterns and common mistakes expert. Handles code review issues with clone abuse, unwrap in production, String misuse, index loops, and refactoring guidance.
Advanced async patterns expert covering Stream implementation, zero-copy buffers, tokio::spawn lifetimes, plugin system scheduling, tonic streaming, and async lifetime management.
Advanced async patterns expert. Handles Stream processing, backpressure control, select/join operations, cancellation, Future trait implementation, and async runtime optimization.
Authentication and authorization expert covering JWT, API keys, OAuth, RBAC, password hashing, distributed token storage, and session management patterns.
Caching and distributed storage expert covering Redis, connection pools, TTL strategies, cache patterns (Cache-Aside, Write-Through), invalidation, and performance optimization.