Based on “The Rust Programming”
Hello, World!
- Rust indent with four spaces, not a tab.
println!
is a Rust Macro,println
is without the!
is a function.- Compile it with
rustc filename
, similar to GCC and Clang.
Hello, Cargo!
- Create a new cargo project with
cargo new project_name
. - It will also initialize a Git repo, Git files won’t be generated if running within an existing Git repo.
- Building new project, run
cargo build
in project’s main directory. - It will create an executable file in
tartget/debug/project_name
. - Run exxcutable with
cargo run
, it will build the project if it hasn’t yet. - Run
cargo check
to check if it will compile. - Run
cargo build --release
to complie it with optimization for release, it will create excutable intarget/release
instead oftarget/debug
.