Curriculum Foundations Bindings and mutability
Bindings and mutability
Rust flips TypeScript's mutability default. Every binding starts immutable; you opt in to mutability with let mut. Type annotations come after the name (let x: i32 = 5), and the numeric primitives are width-specific (i32, u64, f64) instead of TS's single number. Shadowing is allowed and idiomatic because it creates a fresh binding that happens to reuse the name. Planned exercises: 1. choose immutable let. 2. choose let mut. 3. recognise type annotations. 4. distinguish mutation from shadowing. 5. fill mut. 6. fill a type annotation. 7. write a rebinding line. 8. translate several TS bindings. 9. fix a program that tries to mutate an immutable binding.
Exercises
9 ready
01
pick one
The variable is declared and used, never reassigned. Pick the
02
pick one
The variable is reassigned on the next line. Pick the Rust
03
pick one
Rust's numeric primitives are width-specific — there's no generic
04
pick one
The program parses a string and wants to use the same name
05
fill blanks
Fill the keyword that turns this let into a mutable binding so
06
fill blanks
Fill the Rust type annotation. The literal is a 32-bit signed
07
type one line
Write the line that rebinds text to its trimmed length — a
08
write a program
Translate the TypeScript into a complete Rust program. Three
09
write a program
Write a Rust program that increments a counter from 0 to 5 and