4.1.1Semicolon separator¶
Rust code is organized in statements separated by semicolons. In practice, each statement is written on one line and terminated with a semicolon, like in the following example in which two statements are written:
let a = 10;
println!("{a}");10
Since the semicolon is a separator, we may also write those two statements on a single line:
let a = 10; println!("{a}");10
A statement may be divided into multiple lines, for instance to avoid excessive length:
assert_eq!(format!("a {} b {} c {} d {} e {} f {}", 1, 2, 3, 4, 5, 6),
format!("{} 1 {} 2 {} 3 {} 4 {} 5 {} 6", 'a', 'b', 'c', 'd', 'e', 'f'));4.1.2Curly brackets¶
Statements can be grouped using curly brackets:
{
let a = 10;
println!("{a}");
}
{
let b = 15;
println!("{b}");
}10
15
()Curly brackets are also used to delimit the bodies of functions:
fn foo() {
println!("Hello!");
}
foo();Hello!
Or the blocks of control flows:
for i in 0..10 {
print!("{i} ");
}
println!("")0 1 2 3 4 5 6 7 8 9
()4.1.3Naming conventions¶
In Rust, naming conventions (see Naming conventions) are as shown in Table 1.
Table 1:Rust naming conventions
Object | Naming style | Examples |
|---|---|---|
|
|
|
Local variable, function |
|
|
Constant |
|
|