Naming conventions
This chapter covers standard naming conventions.
Casing
In general, use PascalCase
for names of types or traits and use snake_case
otherwise.
More precisely:
Item | Convention |
---|---|
Modules |
|
Types |
|
Traits |
|
Enum variants |
|
Struct fields |
|
Functions |
|
Methods |
|
Variables |
|
Constants |
|
Type parameters |
|
In PascalCase
, acronyms count as one word: use Sha
rather than SHA
.
In snake_case
, acronyms are lower-cased: sha3_hash
.
In snake_case
or UPPER_CASE
, a word should never consist of a single character unless it is
a digit or the last word.
So, we have btree_map
rather than b_tree_map
, but PI_2
rather than PI2
.
Language implementations can emit warnings when names do not follow these rules.
Underscore prefix (e.g. _foo
)
The name of an unused variable must start with an _ (a common example is simply "_").
let _unused = compute_something();
Language implementations can emit warnings when a variable not starting with an underscore is only written-to but is never read. The same applies when a variable starting with an underscore is read.