Rust Guidelines
Asterinas follows the Rust API Guidelines and the project-specific conventions below.
- Naming — CamelCase/acronym style and closure variable suffixes.
- Language Items
- Variables, Expressions, and Statements — Explaining variables, block expressions, and checked arithmetic.
- Functions and Methods — Nesting control, function focus, and boolean-argument avoidance.
- Types and Traits — Type-level invariants, enums for closed sets, and field encapsulation.
- Comments and Documentation — RFC 1574 summaries, comment/doc style, and module docs.
- Unsafety —
// SAFETY:justification,# Safetydocs, and module-boundary reasoning. - Modules and Crates — Visibility control and workspace dependencies.
- Macros and Attributes —
Narrow lint suppression,
#[expect(dead_code)]policy, and macro restraint.
- Select Topics
- Concurrency and Races — Lock ordering, spinlock discipline, atomics, and critical sections.
- Defensive Programming —
Correct use of
debug_assert!. - Error Handling —
Error propagation with
?. - Logging — Standard logging macros and log-level selection.
- Memory and Resource Management — RAII and cleanup by ownership.
- Performance — Hot-path complexity, copy/allocation control, and evidence-based optimization.