Collection of rust programs from the official book The Rust Programming Language.
To start to use rust on UNIX-like system it's enough to run:
$ curl https://sh.rustup.rs -sSf | sh
rustup will install the latest stable version. Then to add cargo to your system PATH
, include the following line to your rc
file:
export PATH="$HOME/.cargo/bin:$PATH"
Firstly check if rust and cargo are properly set:
$ rustc -V; cargo -V
If all is good the output will show the version of both binaries.
🦀
There are 2 different ways to compile rust programs.
Rustc
The 1st using the compiler rustc
. So starting from a classic hello.rs
:
fn main() {
println!("Hello, world!");
}
To compile our function:
$ rustc hello.rs
This will create a binary called hello
, that will print the string Hello, World!
.
Cargo
The 2nd using the package manager cargo
. So running:
$ cargo new hello_world
we can create our first rust package and have a structure like the following:
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
To interact with this package there are several options:
$ cargo check # To check if it is error-proof
$ cargo build # To compile it and store the binary under target/debug
$ cargo build --release # To compile it and store the binary under target/release
$ cargo run # To run the binary
$ cargo update # To update the version of all the dependencies
Hack without fear!
The official docker images:
This work is unlicensed under the terms of Unlicense.