Skip to content

Code style

Dzmitry Malyshau edited this page Feb 14, 2021 · 1 revision

Here are the notes about the recommended code style for Naga.

Includes

Module scope should include the following types:

  • crate::arena::{Arena, Handle} - these are used everywhere
  • crate::proc::<anything>
  • external crate types, if needed. Follow the same principles there: for example, for spirv, Word is used everywhere, so it should be included, but the rest of the types don't need to.

The following types should not be included:

  • crate::<anything>. Use fully qualified types instead in the module.

For referring types in sibling modules of the same backend/frontent, use super::xxx in either includes or fully-qualified names.

In local places (i.e. function bodies) with intense use of a specific crate type, e.g. crate::TypeInner, it's good to define a short alias for it:

use crate::{ScalarKind as Sc, TypeInner as Ti};

Note that we aren't global-importing enum variants (crate::TypeInner::*) because it allows for easy mistakes that only appear as warnings in Rust.

Clone this wiki locally