This repository is for my workings through The Rust Programming Language book, commonly known as "The Rust book".
Conventions
rustup
is used for version management- Indentation is handled with four spaces
- Cargo is used for package management and building systems
- Variables and references are immutable by default
Symbols
- Most Rust lines end with a semicolon
;
- Rust functions are invoked with
functionName()
- Function bodies are wrapped in curly braces
{}
- Rust macros have an exclamation mark after their name
!
- Associations for libraries, functions and type are marked with a double colon
::
- Access a specific piece of code from reference
&
Updating Rust
rustup update
Uninstalling Rust
rustup self uninstall
Compiling a single file
rustc <File.rs>
A basic function
fn <name>() {
}
A basic Rust macro
println!("Hello, world!");
Creating a variable
let variableName = value;
Creating a mutable variable
let mut variableName = value;
Using part of the standard library
use std::io;
Creating a new project
# Creates a project directory
cargo new <project-name>
Validate a project will compile
cargo check
Adding crates (libraries) with cargo
Append the crate to the [dependencies]
section, which follows semantic versioning.
Update project dependencies
cargo update
Running a project
cargo run
Building a project
cargo build
Build a project with release optimisations
cargo build --release