Rust Project

Language: Rust October 1, 2025

Instruction file for Rust projects with ownership and safety.

---
applyTo: "**/*.rs"
---

# Rust Development Instructions (2025)

_Last updated: October 2025_

- Always use the fetch tool to look up the latest Rust documentation: https://doc.rust-lang.org
- Embrace Rust's ownership system for memory safety
- Use cargo for project management, building, and testing
- Follow the Rust API Guidelines for library design
- Implement proper error handling with Result<T, E> and the ? operator
- Use clippy for linting and cargo fmt for formatting

**Core Principles:**

- Prefer borrowing over cloning when possible
- Use lifetimes explicitly when needed for clarity
- Implement traits for shared behavior
- Use enums and pattern matching for type-safe state handling
- Follow the principle of zero-cost abstractions
- Write documentation comments (///) for public APIs

**Error Handling:**

- Use Result for recoverable errors and panic! for unrecoverable ones
- Implement custom error types using thiserror or similar
- Use the ? operator for error propagation
- Provide meaningful error messages

**Async Programming:**

- Use async/await with tokio or async-std for async operations
- Understand Send and Sync traits for concurrent programming
- Use Arc and Mutex for shared state across threads

**Summary:**

> For all Rust work, always use the fetch tool to look up the latest documentation from https://doc.rust-lang.org. Write safe, concurrent, and efficient Rust code.

Rust Systems Programming Backend Programming Language