Rust 101 Course Notes

How to Use This

As you go through the course:

  1. Capture what clicks - when something makes sense, write it in YOUR words

  2. Capture what confuses - come back to it, ask me

  3. Code snippets - copy patterns you’ll reuse


Section 2: Variables & Data Types

2.a: Data Types

Key Insight

Memory only stores binary data. The program determines what that binary represents.

Rust provides basic types that are universally useful:

Type Description Examples

Boolean

Logical true/false

true, false

Integer

Whole numbers (positive and negative)

1, 2, 50, 99, -2

Float

Decimal numbers (double precision)

1.1, 5.5, 200.0001, 2.0

Character

Single character (in single quotes)

'A', 'B', '6', '$'

String

Text (in double quotes)

"Hello", "it’s 42"

2.b: Variables

Variable

Assigns data to a temporary memory location. Can be set to any value and type.

Immutability by Default

Rust variables are immutable by default. This is intentional:

  • Easier to reason about programs

  • Less likely to make programming errors

  • Increases speed of the program

Use mut keyword to make a variable mutable.

Immutable

Cannot be changed after assignment

Mutable

Can be changed (requires mut keyword)

Variable Examples
// Immutable variables (default)
let two = 2;
let hello = "hello";
let j = 'j';
let my_half = 0.5;
let quit_program = false;

// Mutable variable (can be changed)
let mut my_name = "Bill";
my_name = "Bob";  // OK - it's mutable

// Using a previously defined variable
let your_half = my_half;