]> git.lizzy.rs Git - rust.git/blob - src/doc/style-guide/src/advice.md
Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errors
[rust.git] / src / doc / style-guide / src / advice.md
1 # Other style advice
2
3 ## Expressions
4
5 Prefer to use Rust's expression oriented nature where possible;
6
7 ```rust
8 // use
9 let x = if y { 1 } else { 0 };
10 // not
11 let x;
12 if y {
13     x = 1;
14 } else {
15     x = 0;
16 }
17 ```
18
19 ## Names
20
21  * Types shall be `UpperCamelCase`,
22  * Enum variants shall be `UpperCamelCase`,
23  * Struct fields shall be `snake_case`,
24  * Function and method names shall be `snake_case`,
25  * Local variables shall be `snake_case`,
26  * Macro names shall be `snake_case`,
27  * Constants (`const`s and immutable `static`s) shall be `SCREAMING_SNAKE_CASE`.
28  * When a name is forbidden because it is a reserved word (e.g., `crate`), use a
29    trailing underscore to make the name legal (e.g., `crate_`), or use raw
30    identifiers if possible.
31
32 ### Modules
33
34 Avoid `#[path]` annotations where possible.