Indentation and Whitespace
Indentation
- Use spaces, not tabs.
- Each level of indentation must be four spaces (that is, all indentation outside of string literals and comments must be a multiple of four).
- The maximum width for a line is 100 characters.
fn main() {
println!("HelloWorld");
}
Blank lines
Separate items and statements by either zero or one blank lines (i.e., one or two newlines). E.g,
fn foo() {
let x = ...;
let y = ...;
let z = ...;
}
fn bar() {}
fn baz() {}
Whitespace
-
Lines must not exceed 99 characters.
-
No trailing whitespace at the end of lines or files.
Space
- Use spaces around binary operators, including the equals sign in attributes:
fn test () -> i32 {
a + b
}
- Use a space after colons and commas:
fn foo(a: Bar);
MyStruct { foo: 3, bar: 4 }
- Use a space after the opening and before the closing brace for single line blocks or struct expressions:
fn test () -> i32 {
a + b
}
Point { x: 0.1, y: 0.3 }