Installation
https://doc.rust-lang.org/book/ch01-01-installation.html#installation
in linux or Mac
$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
in windows
visit https://www.rust-lang.org/tools/install
Create New Project
Manual
|
|
save into main.rs and run it by rustc main.rs | ./main
With Cargo
run
|
|
Looping
Infinite loop
use infinite loop
|
|
For Loop
example:
|
|
note:
- use
1..=6if want to count6 - if
.iter()removed, linelet dog = animals[1];will be error - if we want to iter index of the array, use
enumerate()1 2 3for (index, animal) in animals.iter().enumerate() { println!("{}: {}", index, animal); }
Enum
outside main func create enum like this:
|
|
to access variant in enum, we use double collon ::.
Put this in the main func
|
|
Constant
constant should be upper-snack case like this
|
|