# Rust

> Guides Rust development with best practices for ownership, error handling, idioms, performance, and async patterns.

- Skill: `diegosouzapw/rust` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add diegosouzapw/rust`
- Raw SKILL.md: https://api.skillmd.com/api/skills/diegosouzapw/rust/raw
- Safety review: PASS (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools, Productivity
- Tags: Async, Clippy, Error Handling, Ownership, Performance, Rust, Tokio
- Author: diegosouzapw (https://skillmd.com/u/diegosouzapw)
- Updated: 2026-08-22
- Page: https://skillmd.com/skills/diegosouzapw/rust

---


# Rust Best Practices

## Ownership & Borrowing
- Prefer borrowing over ownership transfer
- Use &str for function parameters over String
- Clone only when necessary
- Use Cow<str> for maybe-owned strings

## Error Handling
- Use Result<T, E> for recoverable errors
- Use panic! only for unrecoverable errors
- Use ? operator for error propagation
- Create custom error types with thiserror
- Use anyhow for application errors

## Idioms
- Use iterators over manual loops
- Prefer pattern matching with match
- Use Option for optional values
- Use derive macros for common traits
- Use clippy for linting

## Performance
- Use release builds for benchmarks
- Profile before optimizing
- Consider using Box for large stack types
- Use Arc/Mutex for shared state

## Async
- Use tokio or async-std runtime
- Use async/await for async code
- Avoid blocking in async context
- Use channels for async communication

