forked from inancgumus/learnrust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
31 lines (27 loc) · 803 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
let x = 5;
println!("x: {}", x);
// x variable is immutable.
// so we can't change its value.
// x = 6;
// but we can declare a new variable,
// with the same name: `x`.
//
// this way, we don't need to imagine
// new variable names.
let x = 6;
println!("x: {}", x);
// we can also create a constant.
// constant are compile-time values.
// so, anywhere MAX_VALUE appears, the
// compiler will change it with 10 instead.
//
// instead of using hardcoded values, use
// constants instead.
const MAX_VALUE: u32 = 10;
println!("MAX_VALUE: {}", MAX_VALUE);
// SHADOWING
let spaces = " "; // &str
let spaces = spaces.len(); // usize
println!("spaces: {}", spaces);
}