Code Style
The conventions for code in the engine workspace: formatting, lints, comments, module layout, naming and dependencies.
Formatting
Default rustfmt. There is no rustfmt.toml in the tree, so the standard style applies everywhere. Run cargo fmt before committing, and do not reformat files you did not otherwise change.
CI has no cargo fmt --check gate; it is a courtesy that keeps diffs reviewable.
Lints
CI denies every clippy warning, with two exceptions that are inherent to Bevy systems and queries:
cargo clippy --workspace --no-deps --exclude bevy_hui -- \
-D warnings \
-A clippy::too_many_arguments \
-A clippy::type_complexity
xtask and tools/updater are separate workspaces and are linted separately, also with -D warnings. While iterating, lint the crate you are working on with cargo clippy --profile dist -p <crate>; renzora check runs in the container if you want the whole workspace without a second artefact tree on your machine.
Do not paper over a lint with #[allow(...)]. Fix it, or add a one-line comment saying why the allow is correct.
Every crate opts into the workspace lint table:
[lints]
workspace = true
The table ([workspace.lints.rust] in the root Cargo.toml) is currently empty, but it must exist because every crate inherits from it. Keep the block in new crates so they pick up any lint added later.
No em dashes. Anywhere.
Never use an em dash (U+2014), or an en dash (U+2013) as punctuation: not in code, comments, doc-comments, markdown, commit messages, release notes, UI strings, log lines, error text or panic messages. There is no exception for "it reads better here".
Almost every em dash is one of four other marks in disguise, and choosing the right one says what the dash left ambiguous:
| When the second half... | Use |
|---|---|
| explains the first | a colon |
| is an aside | a comma, or parentheses |
| is a second, joined clause | a semicolon |
| is a new thought | a full stop and a new sentence |
A hyphen in an identifier, a flag or a range is fine, and so is a minus sign in a numeric diff.
Comment the why
This codebase's hallmark is doc-comments (//! on a module, /// on an item) that explain why the code is shaped the way it is: what edge case it handles, what constraint forces it, what goes wrong if it is changed. Match that density and voice.
Do not add narration that restates the code. A comment that says what the next line does is noise; a comment that says why the obvious alternative does not work is the most valuable thing in the file.
/// Held for the life of the process, never dropped.
///
/// Every system the plugin registered is a function pointer into this image,
/// so unmapping it would leave the schedule calling into freed memory.
/// Disabling a plugin therefore takes effect on the next launch.
Write comments in plain language. Say what happens and why, as you would to a colleague reading the file for the first time.
Module layout
A crate keeps one plugin and its module doc in lib.rs, its systems in systems.rs, and one module per thing the crate builds: panel.rs, graph.rs, inspector.rs, drawer.rs. Inside a module, order items as types, then systems, then helpers.
Name a module for what it is, never for what it is not. A module or type named for a distinction that no longer exists (a native_ prefix from when a UI had two implementations, say) names nothing. A panel type is a FoliagePanel, not a NativeFoliage. The one place native still means something is a #[cfg(not(target_arch = "wasm32"))] gate, and there it names a platform.
Long files
A file past about 1,500 lines wants splitting, into a directory of modules named for the sections it already has: foo.rs becomes foo/mod.rs plus siblings, with a flat pub use so every path a caller writes still resolves.
The exception is a single exhaustive match over a large enum. It is long because the compiler is proving every variant is handled, and splitting it into per-group functions would need a _ => arm in each, which turns a compile error into a silent run-time one. Length there is the price of the proof.
Naming
| Item | Convention | Example |
|---|---|---|
| Types, traits, enum variants | PascalCase | PhysicsPlugin, Scope::Runtime |
| Functions, methods, variables, fields | snake_case | spawn_entity, player_health |
| Modules and files | snake_case | scene_io.rs |
| Constants and statics | SCREAMING_SNAKE_CASE | MAX_CLIENTS |
| Engine crates | renzora_<name> | renzora_physics |
| Contract layers | renzora_<job>_api, in crates/api/ | renzora_scene_api |
| Editor half of a split crate | renzora_<name>_editor, in crates/renzora_<name>/editor/ | renzora_physics_editor |
Plugin types end in Plugin, and an editor half's plugin is <Name>EditorPlugin (PhysicsEditorPlugin). Vendored crates keep their upstream names.
Dependencies
[package]
name = "renzora_myfeature"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = { workspace = true }
renzora_scene_api = { path = "../api/renzora_scene_api" }
[lints]
workspace = true
- Bevy comes from the workspace (
bevy = { workspace = true }), which points atbevy/. Never name a version or a registry copy. - Depend on the contract layers you use, never on another engine crate's internals, and never on
renzora_sdk. Depend on the lowest crate that has the name you need. When a type must cross a crate boundary, move it into the contract rather than depending on the crate that defines it. See the contract. - The editor contract is opt-in.
renzora's default features are empty; a crate that derivesInspectableor uses the inspector, toolbar or shortcut registries depends onrenzora_editor_api(or onrenzorawithfeatures = ["editor"]). A crate that ships in games keeps that dependency optional behind its owneditorfeature. - Nothing built on Bevy from crates.io. Copy it into
vendor/, point its Bevy dependency atbevy/by path, and add it to the workspace.cargo renzora check-bevyfails the build otherwise. - Keep dependencies few. A crate with many dependents passes every edit below it on to all of them.
Bevy idioms
- Follow Bevy's ECS patterns: systems, components, resources, messages, observers. Order systems with system sets rather than plugin priority.
- When Bevy removes something, move to what Bevy offers instead. Read the removing pull request or the deprecation note and migrate every caller. Never re-create the removed API on Renzora's side: a port of deleted Bevy code is a fork that drifts further from everything around it.
- Never edit
bevy/. If a change seems to need one, describe it to the maintainer and work around it from Renzora's side.
Errors and panics
| Context | Approach |
|---|---|
| A library with a real error domain | a thiserror error enum (as renzora_engine, renzora_import, renzora_rmip and others do) |
| A fallible function | return Result and propagate with ? |
| A Bevy system | log and continue (warn!, error!), or return a Result and let Bevy's error handling report it |
| A genuinely infallible operation | .expect("the reason it cannot fail") |
Avoid bare unwrap() in production paths; tests may use it freely.
In the editor, a panicking system is caught by Bevy and logged to the Console rather than crashing the editor, but a shipped game keeps Bevy's default handler and a panicking system ends the game. Write systems as if every panic were fatal, because in the game it is.
Unsafe code
Avoid unsafe unless it is genuinely necessary. The legitimate places are few: loading a plugin or the editor image and looking up its entry symbol, and GPU or OS interop. Every unsafe block carries a // SAFETY: comment stating the invariant that makes it sound.
Commits
Conventional Commits, type(scope): subject, imperative mood, no trailing period. See Contributing Guide.