The repository's own Rust rules. General Rust idioms apply on top of these; AGENTS.md has the overall code quality rules.
- Pinned toolchain in
rust-toolchain.toml, with thewasm32-unknown-unknowntarget. Upgrades happen in their own commit. - Edition 2024, set once in
[workspace.package]. - Lints are set in the workspace
Cargo.tomland inherited with[lints] workspace = true:unsafe_codeis forbidden;clippy::allandclippy::pedanticare on, with the few noisy pedantic lints allowed there, never in code;- warnings fail CI.
#[allow(...)]in code needs a short reason next to it.
- Module files:
foo.rsnext to afoo/directory, neverfoo/mod.rs. - One concept per module: each public type and each concern in a file of its own.
- Visibility:
pubonly for the crate's API;pub(crate)for the rest. - Types, fields and enum variants are named with nouns for what they are, not clauses or verbs. Functions are verbs, and booleans read as a statement.
- Ask first. A new dependency is proposed to the maintainer with the reason and the alternatives before it is added.
- Versions live in
[workspace.dependencies]; crates usedep.workspace = true, adding the features they need. The Tauri plugin, outside the workspace, keeps its own. - Every crate declares
rust-version, the pinned toolchain's ([workspace.package]), and a published crate anincludelist: its sources, its README and its licence, never its tests and benchmarks. - cargo-deny must pass: licences, advisories, bans.
- Every Rust command-line tool parses its arguments with
clapusing the derive API (#[derive(Parser)], subcommands as an enum).
- Library crates define typed error enums with
thiserror, one per crate or per area, with variants callers can act on. - Binaries may use
anyhowto add context at the top level. - No
unwrapoutside tests.expectonly for a proven invariant, with a message saying why it can't fail. - Errors never contain a document's content, so they are safe to log.
- Libraries emit structured events and spans with
tracing. Only binaries install a subscriber. - Never log a document's content; log positions, counts and timings.
- Every public item gets a
///doc comment: what it does, and its arguments where not obvious. - Public functions that can fail have an
# Errorssection; key APIs have a runnable# Examplesdoctest. - Each crate's
lib.rsstarts with a//!summary pointing to its spec sections and designs. - No other comments unless the code can't say it: a non-obvious reason, an invariant or a link to a decision.
- Unit tests stay with the code they test, in a
#[cfg(test)] mod testsat the bottom of its file, while the file reads well as a whole. - When the tests hurt the code's readability, they move out to a file of their own,
foo/tests.rs, declared at the bottom offoo.rswith#[cfg(test)] mod tests;. When that file grows large,foo/tests/holds one file per group of behaviours. - Integration tests are one test binary per package,
tests/<name>.rswhile it is one file andtests/<name>/main.rsonce it has more, named for what they test, with a module per area and their shared helpers incommon.rs. Each file directly intests/would be a test binary of its own, linking the library again, and a helper that one of them doesn't use would be dead code in it (why). - About 400 lines is a guideline for when a file reads badly, not a threshold. Judge how the tests affect reading the code before splitting. Test data (fixtures, tables of cases) may be longer, in files of its own.
- Property tests with
proptestfor algebraic code. - Benchmarks use
criterionand live in the crate'sbenches/directory. - Test names say the behaviour:
rename_keeps_values, nottest_rename. - Rust crates keep at least 99% line coverage (
cargo make coverage).