Getting started with Rust
Setup
On MacOS or Linux, run this command in the terminal (then follow the instructions):
More: https://www.rust-lang.org/learn/get-started
shcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Get the current Rust & Cargo versions:
shrustc --version cargo --version
Update Rust:
shrustup update
Cargo utils:
sh# create new project cargo init # compile & execute cargo run # build project cargo build # test project cargo test # build documentation cargo doc # add crate cargo add <name>
Source: https://www.rust-lang.org/learn/get-started
You can also install the Rust VSCode extension from here
First Project
With Cargo
Create a new folder then init a rust project with cargo init. This command will create Cargo.toml & src/main.rs with a Hello World example. Run the project with cargo run.
shmkdir new-project cd new-project cargo init cargo run
Without Cargo
Create a file named main.rs with:
rustfn main() { let hello = "Hello World"; println!("{}", hello) }
Compile it with rustc main.rs then run it with ./target/debug/main (.\target\debug\hello.exe on Windows)