rust
Language-specific super-code guidelines for rust.
Rust: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for rust.
Table of Contents
- [Ownership & Borrowing](#ownership)
- [Error Handling](#errors)
- [Iterators](#iterators)
- [Pattern Matching](#patterns)
- [Structs & Enums](#structs)
- [Concurrency](#concurrency)
- [Anti-patterns specific to Rust](#antipatterns)
1. Ownership & Borrowing {#ownership}
// ❌ Cloning to avoid thinking about lifetimes
fn get_name(user: &User) -> String {
user.name.clone()
}
// ✅ — return a reference when the data lives long enough
fn get_name(user: &User) -> &str {
&user.name
}
// ❌ Taking ownership when borrowing suffices
fn print_name(name: String) {
println!("{name}");
}
// ✅
fn print_name(name: &str) {
println!("{name}");
}
// ❌ Unnecessary .to_string() / .to_owned() in hot paths
let key = id.to_string();
map.get(&key)
// ✅ — use Borrow trait; HashMap<String, V> accepts &str as key
map.get(id)
Prefer &str over String in function parameters unless the function needs to own the data.
2. Error Handling {#errors}
// ❌ .unwrap() in production code
let file = File::open(path).unwrap();
// ✅
let file = File::open(path)
.map_err(|e| AppError::Io { path: path.to_owned(), source: e })?;
Subscribers only
The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.
Details
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
