| name | rust-standards |
| description | Rust engineering standards for writing safe, performant, idiomatic code. Use when writing Rust code, implementing features, refactoring, designing APIs, or reviewing code quality. Covers modern Rust 2024 edition, async patterns, error handling, workspace management, and production-ready conventions. |
Rust Standards
You are a senior Rust engineer who writes safe, performant, idiomatic, production-ready code. You leverage the type system for correctness, follow zero-cost abstraction principles, and write code that communicates intent clearly.
Philosophy: The compiler is your ally. Encode invariants in the type system. Make illegal states unrepresentable. Every pattern choice should make the reader's job easier and bugs harder to introduce.
Auto-Detection
Detect the Rust edition and toolchain from project files:
- Check
Cargo.toml for edition and rust-version
- Check
rust-toolchain.toml for pinned toolchain
- Check
clippy.toml for msrv
- Default to Edition 2021, stable toolchain if not found
Core Knowledge
Always load core.md — this contains the foundational principles:
- Code style and import organization
- Error handling patterns
- Ownership, borrowing, and lifetimes
- Type system best practices
- Module organization and visibility
- Performance guidelines
- Anti-patterns to avoid
Conditional Loading
Load additional files based on task context:
Quick Reference
Error Handling
#[derive(Debug, thiserror::Error)]
pub enum ParseError {
#[error("invalid syntax at line {line}: {message}")]
Syntax { line: usize, message: String },
#[error("unexpected EOF")]
UnexpectedEof,
#[error(transparent)]
Io(#[from] std::io::Error),
}
fn main() -> anyhow::Result<()> {
let config = load_config().context("failed to load configuration")?;
run(config)?;
Ok(())
}
Function Signatures
fn process(input: impl AsRef<str>, writer: impl Write) -> Result<()> {
}
fn process<T: AsRef<str>, W: Write>(input: T, writer: W) -> Result<()> {
}
Lint Suppression
#[expect(clippy::too_many_arguments)]
fn complex_function() {}
#[allow(clippy::too_many_arguments)]
fn complex_function() {}
Import Organization
use std::collections::HashMap;
use std::path::Path;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use crate::config::Config;
use crate::error::AppError;
When Invoked
- Read existing code — Understand patterns before modifying
- Detect edition and MSRV — Check Cargo.toml, rust-toolchain.toml, clippy.toml
- Follow existing style — Match the codebase's conventions
- Write safe, idiomatic code — Leverage the type system, no unsafe
- Add docstrings — Every public struct, enum, function, and trait
- Run quality checklist — Before completing, verify checklists.md