Install Rust (RustUp - the Rust environment manager):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-- https://www.rust-lang.org/tools/install
In println!()
, the exclamation mark !
means the call is aimed at a macro.
Only double quotes form strings in Rust. Single quotes ('
) form a different kind of value. Something called a "char", and chars are only allowed to have single characters inside them.
For binding methods to data, Rust uses a concept it calls a struct
. This is similar to a class
in Python or C++.
Struct example - a new type of value inside our program, for a deck of cards:
struct Deck {
cards: Vec<String>,
}
A vector
in Rust can change its size, and an "array" cannot.
A unit test in Rust looks like this:
static MESSAGE: &'static str = "Hello, world!";
#[test]
fn message_is_correct() {
assert_eq!(MESSAGE, "Hello, world!");
}
Run the tests with: cargo test
.