I first came across Rust through a project named Servo. Rust was born out of an attempt to rewrite the rendering engine behind Firefox. Since then it has been voted the “most loved language” at least two years in a row (see Stack Overflow Developer Survey 2017).

The best way to learn Rust is by reading the second edition of the official book. I purchased a copy of the book and the following are notes I took while reading the book or other resources.

One of the first things you’ll notice immediately is that println is a macro, not a function. More generally, this is how metaprogramming is done in Rust. For example, if you would like to write a routine that takes a variable number of arguments or has default values you’ll need to write a macro.

Another important bit of syntax is the semicolon, which terminates an expression.

Cargo can be used to create a project, build the code, download and manage dependencies. This becomes increasingly important because the standard library in Rust is relatively small. When creating a project use --bin to specify building a application. Cargo will initialize a git repository by default. It manages dependencies for a project by generating a Cargo.lock file.

// A string literal is simply an immutable String reference
let sl = "Hello world";
// Create a String from a string literal
let s = String::from("Hello world");
struct Person {
    name: String
}
let name = String::from("John");
Person {name};
use std::collections::HashMap;

let teams  = vec![String::from("Blue"), String::from("Yellow")];
let initial_scores = vec![10, 50];

let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect();

Comparison to C

Resources

Articles

Applications

Other