Rust Notes
Notes from learning the Rust language. Using the Brown University experimental fork of “The Rust Programming Language” book.
Rust Basics
Some of the basic bits of information.
rustccommand builds rust executables.- The
rustupcommand can be used to update rust on your system..
Cargo
Cargo is a build system and package manager for Rust. It also does a number of project management tasks like creating git repos, config files and setting up directory structures for a project automatically.
Cargo Commands
cargo new project_namecreates a new project with cargo.cargo buildbuilds a project, an executable will be placed in the target/debug directory.cargo runbuilds a project and executes it.cargo checkchecks the code without building.- To build a project with optimisations, the
--releaseflag can be added. This will place the executable in target/release.
Syntax and writing Rust
Rust syntax has some similarities to other programming languages like C.
Rust Basics
Some of the basic bits of information.
- Functions in rust are denoted by
fn, the contents must be contained by{}brackets.. - The
mainfunction is the first one ran in a rust program.
Using Libraries
Only a subset of Rust’s standard library is available automatically in a project, this set is known as the prelude. The following is information on how to use other part of the standard library, or other libraries.
- The
usestatement allows you to bring specific types from the standard library into a project. This is done by calling it’s specific library after the parent library likestd::io. - The
mainfunction is the first one ran in a rust program.
use std::io;
#use library_name::sub_library;