Skip to content
academia.sh

Course Beginner

Rust Fundamentals

Published Updated

By the end of this course

Start course

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.

  1. 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?
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

02

Data Modeling

Gathering fields and methods under a single type, counting states under a single type through data-carrying variants, pattern matching's need for exhaustiveness and destructuring, the difference between a growable array and a key-value structure, the separate guarantees given by ordered and hash-based structures, and what a module boundary means for visibility.

  1. 01 Structs The same Point value is built three separate ways — full syntax, update syntax, associated function — and all three produce a value as an expression; the struct declaration itself produces no value, it only introduces a name the following lines can use.
  2. 02 Enums A Shape value can be constructed in three separate forms — carrying no data, carrying one number, carrying two numbers — and all three are counted under the same type; constructing a variant is an expression, the enum declaration itself is an item. The limiting measurement shows that variant count must not be confused with state count.
  3. 03 Pattern Matching The same Circle(5.0) value is taken apart by three separate pattern forms — exact, binding, guarded — and match itself, as an expression, gives the same type across every arm. The limiting measurement shows that a catch-all arm provides exhaustiveness but can silently swallow a new variant.
  4. 04 Collections The same 'mutate' work is measured across three separate collections but falls into one of two classes: the growable array's push gives () (statement), the hash map's insert gives the old value as an Option (expression). The limiting measurement shows that old data is silently lost if this return value is not captured.
  5. 05 Ordered and Set Structures The same four keys are put into an ordered map and a hash map: the ordered map's traversal gives the same order on every run, the hash map's is never printed — this is the course's most concrete example of the data-must-not-depend-on-the-environment rule. The limiting measurement shows that the ordering guarantee depends on a condition, using the Point type from the Structs lesson.
  6. 06 Modules and Crates mod and use are both items: neither produces a value on its own, one draws a name boundary, the other shortens an existing path. The same name is called both from inside and outside the module, and pub versus non-pub cases are compared; two separate source files are compiled with a single rustc call and produce a single crate. The limiting measurement shows that visibility must be granted separately at every link of the path: even if an item is pub, it is unreachable from outside if the module wrapping it is not pub.

Final exam

Rust Fundamentals — Final Exam

In preparation

This course's question bank is not complete yet. The exam opens here automatically once enough questions are added.

Start typing to search.

↑↓ ↵ Esc navigate · open · close