Skip to content

Code formatting guideline#

This document provides code formatting rules that should be enforced for new code.

General#

  • G-01: Format code as cargo fmt does.
  • G-02: If cargo fmt does not enforce anything at all (e.g., macros), try format to format it in a rusty way.
  • G-03: Try to avoid overly long lines even if cargo fmt does not complain.

Imports#

  • I-01: Always put external imports (including sibling crates) first, in alphabetical order, followed by crate-internal imports (crate::) and, afterwards, relative imports.
  • I-02: Group all imports from the same crate into a block (alphabetically ordered) that is separated from other blocks with an empty line.
  • I-03: Always use self:: or super:: for relative imports.