BACK TO TEMPLATES
rulesany

Rust Backend Rules

Production AGENTS.md for Rust codebases specifying Cargo workspace layout, error handling with anyhow, and clippy checks.

When to use this

Place this template at the root of a Rust project or Cargo monorepo to enforce Rust safety, zero-warning clippy policies, and idiomatic error handling.

The template

# AGENTS.md

## Project Context

High-performance Rust backend service utilizing Tokio async runtime and Axum framework.

## Commands

- `cargo run` launch application binary
- `cargo test` run unit and integration tests
- `cargo clippy -- -D warnings` check lint rules with zero warning tolerance
- `cargo fmt --check` check code formatting compliance

Always run `cargo clippy -- -D warnings` and `cargo test` before declaring code complete.

## Conventions

- Derive explicit error types using `thiserror` for library code or `anyhow` for applications.
- Never use `unwrap()` or `expect()` in production paths. Handle `Option` and `Result` explicitly.
- Prefer borrowing (`&str`, `&[T]`) over allocation (`String`, `Vec<T>`) where appropriate.
- Keep module structure clean: export public APIs in `lib.rs` or `mod.rs`.

## Strict Restrictions

- Do not introduce `unsafe` code blocks without explicit maintainer approval.
- Do not add new external crates to `Cargo.toml` without checking existing dependencies.
- Do not disable clippy warnings inline (`#[allow(...)]`) without documented justification.

## Approval Required

- Adding new crate dependencies.
- Modifying `unsafe` blocks or FFI boundaries.
- Database schema changes or raw SQL migrations.

Customization Guide

Adjust framework details (e.g. Tokio, Axum, Actix) to match your crate setup.

Last verified 2026-07-26