rust
What it does
This guide provides best practices for writing efficient and idiomatic Rust code. It teaches how to correctly use language features like 'ownership' and 'borrowing', handle errors robustly, and effectively utilize iterators and pattern matching.
When to use it
- βWhen learning Rust's fundamental concepts.
- βWhen refactoring existing Rust code for better efficiency.
- βWhen debugging common Rust errors.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/rust/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I avoid unnecessary data cloning in Rust?β
5 new skills a week. 1 minute to read.
How it works
The AI compares 'bad' code examples with 'good' Rust code examples. It explains the principles behind best practices, such as preferring references (`&str`) over copies (`String`) and using the `?` operator for error handling.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
- Error Handling
- Iterators
- Pattern Matching
- Structs & Enums
- Concurrency
- Anti-patterns specific to Rust
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 })?;
// β Manual match on Result for every call
match do_thing() {
Ok(v) => v,
Err(e) => return Err(e),
}
// β
β the ? operator
let v = do_thing()?;
// β Box<dyn Error> everywhere (loses type info)
fn run() -> Result<(), Box<dyn std::error::Error>> { ... }
// β
β use thiserror for library errors, anyhow for application errors
use anyhow::{Context, Result};
fn run() -> Result<()> {
do_thing().context("failed during run")?;
Ok(())
}
// β Separate error enum variant for every call site
enum Error { FileOpen, FileRead, Parse, Network, ... }
// β
β use thiserror with #[from] for automatic conversion
#[derive(thiserror::Error, Debug)]
enum Error {
#[error("io error")] Io(#[from] std::io::Error),
#[error("parse error")] Parse(#[from] serde_json::Error),
}
3. Iterators {#iterators}
// β Imperative accumulation
let mut result = Vec::new();
for item in &items {
if item.active {
result.push(item.name.to_uppercase());
}
}
// β
let result: Vec<_> = items.iter()
.filter(|i| i.active)
.map(|i| i.name.to_uppercase())
.collect();
// β Manual sum
let mut total = 0;
for order in &orders { total += order.amount; }
// β
let total: u64 = orders.iter().map(|o| o.amount).sum();
// β Index-based loop
for i in 0..items.len() {
process(&items[i]);
}
// β
for item in &items {
process(item);
}
// With index:
for (i, item) in items.iter().enumerate() {
process(i, item);
}
Chain iterators lazily; only .collect() when you actually need a concrete collection.
4. Pattern Matching {#patterns}
// β if-let chain that should be match
if let Some(x) = opt {
if x > 0 {
use(x)
}
}
// β
if let Some(x) = opt.filter(|&x| x > 0) {
use(x)
}
// or match with guard:
match opt {
Some(x) if x > 0 => use(x),
_ => {}
}
// β match with identical arms
match status {
Status::Active => true,
Status::Pending => true,
Status::Inactive => false,
}
// β
matches!(status, Status::Active | Status::Pending)
// β Destructuring in body instead of pattern
fn area(shape: &Shape) -> f64 {
match shape {
Shape::Circle(c) => { let r = c.radius; r * r * PI }
Shape::Rect(r) => { let w = r.width; let h = r.height; w * h }
}
}
// β
β destructure in pattern
match shape {
Shape::Circle(Circle { radius, .. }) => radius * radius * PI,
Shape::Rect(Rect { width, height }) => width * height,
}
5. Structs & Enums {#structs}
// β Enum variant carrying bool for binary state
enum State { Running(bool) } // true = paused?
// β
β explicit variants
enum State { Running, Paused, Stopped }
// β Struct with many Option fields (stringly optional)
struct Config {
timeout: Option<u64>,
retries: Option<u32>,
base_url: Option<String>,
}
// β
β use Default + builder pattern or #[derive(Default)] with sensible defaults
#[derive(Default)]
struct Config {
timeout: u64, // default 0 = no timeout
β¦
FAQ
What are 'ownership' and 'borrowing'?
'Ownership' is how Rust manages memory: each value has an owner. 'Borrowing' allows you to temporarily lend access to a value without transferring ownership.
Why should I avoid `.unwrap()`?
`.unwrap()` can cause unexpected crashes in your program if the value isn't what's expected. It's better to use the `?` operator or `match` for safe error handling.
What are iterators in Rust?
Iterators are an efficient way to process data collections, allowing you to chain operations like filtering and mapping elements before collecting the final result.
Details
Original description by the author
Language-specific super-code guidelines for rust.
Popularity
- GitHub stars
- 48k
- Ranking position
- #5898
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.