01
Language Basics
The language's design goals tied to the trade-off between guarantees and cost, project layout established through the manifest, immutability as the default and the opening shadowing gives it, the value ranges primitive types carry, a body's last line as its return value, and whether conditional and loop forms produce a value.
- 01 Rust's Design Goals A measurement core of eighteen writings runs from inside the program and places each writing into one of three classes — expression, statement, item; the result is fixed at eight expressions, five statements, five items, and the rest of the course carries this trio forward as a single question: does what is written in the source produce a value?
- 02 Setup and the Package Manager There are three parts a source is required to write for it to turn into a runnable binary — the entry point, the crate root, the manifest; all three are items, none of them produces a value on its own, but the three together produce a single output, and a change in the manifest can change that output's name without ever touching the source.
- 03 Variables and Immutability let is a binding statement and the assignment itself produces (); the same name being rebound three times (shadowing) and bound once and changed twice (mut) reach the same numeric result, but only shadowing can change the type along the way — because one sets up a new binding each time, the other writes over an existing binding.
- 04 Primitive Types Integer, floating-point, boolean, character, and tuple — five primitive types that produce five separate values when run as expressions; but there is a sixth type too — (), the type with a single value — and that what a statement produces is not nothingness but exactly this type's one value is shown by printing the two values side by side in the same run.
- 05 Functions and Expression Orientation A function's body is a block, and a block is already an expression: if the last line has no semicolon, that is the body's — and therefore the function's — return value; add a semicolon and the body returns (); the semicolon discards the value, but the discarded value's computation still happens, and this is shown through the discarded value's own side effect.
- 06 Control Flow if, match, loop, while, for — of the five control-flow forms, only three can produce a value: if and match are each an expression and require all their branches to give the same type, loop gives a value only through break, while and for never do; a labeled break can carry a value directly out of nested loops.