Skip to content

Restructure chapters and teach ownership as a spiral#31

Merged
mre merged 5 commits into
mainfrom
restructure-chapters
Jun 21, 2026
Merged

Restructure chapters and teach ownership as a spiral#31
mre merged 5 commits into
mainfrom
restructure-chapters

Conversation

@mre

@mre mre commented Jun 21, 2026

Copy link
Copy Markdown
Member

This reorders the course to the layout we planned and changes how ownership is taught.

Instead of one big ownership chapter, ownership is now a spiral. The strings chapter plants the 30-second version (one owner, dropped at end of scope, borrow without taking). A new Moves & Copy chapter comes right after strings, where the first move actually bites. A new Borrowing & references chapter comes right after functions, where you start wanting to pass a value without giving it up. The old ownership chapter becomes a late Memory & ownership chapter that ties the three rules together and adds a gentle lifetimes intuition (no syntax, just the shape of the error). Its exercises were donated to the two early chapters, so nothing is lost.

The ? operator moves up to sit right after Result, where it belongs. To keep it focused, every exercise there now uses a single error type (the old multi-error file exercise became a parse-only sum). The Box material moves to the env-file parser, which is the first place that genuinely mixes file I/O and parse errors. Smart pointers and the password validator are now bonus chapters at the end.

Along the way I fixed the cross-references that the reorder broke (ownership and borrowing now read as already-taught rather than "later"), turned the remaining numeric "chapter N" mentions into names, dropped two banned tics (the "lightbulb moment" line and the "magpie" opener), and added a short appendix page explaining why the course is built this way.

On existing students' progress: migration 010 remaps submissions.exercise_name to the new layout. I built it from the real production snapshot (analysis/course.db, 58 participants, 1359 rows) rather than guessing, so it maps each actual key straight to its final home, including the per-chapter step renumberings the snapshot predates. I validated it against a copy of that snapshot: all 73 surviving distinct keys land on real exercise files. About 180 rows stay put because they belong to exercises that were removed entirely (count_items, countdown, fallback, frequent_words, char_classes, advisor, status, records, number_to_string) and have nowhere to map; nothing is deleted, so no data is lost. The migration runs automatically at server startup. So students keep their progress for every exercise that still exists.

Local CI is green: fmt, clippy, tests, check-examples, check-solutions (75/75), typos, and lychee. Worth eyeballing the TOC, progress count, and the next-chapter button once it's deployed, since the two bonus chapters are now interspersed in the ordering.

mre added 5 commits June 21, 2026 15:40
Reorders the course to the target layout and splits the single
ownership chapter into a spiral: a short seed in the strings chapter,
a Moves & Copy chapter right after strings, a Borrowing & references
chapter right after functions, and a late Memory & ownership chapter
that consolidates the model and adds a gentle lifetimes intuition.

Also moves the ? operator up to sit right after Result and keeps it to
a single error type per exercise (the multi-error file exercise is now
a parse-only sum). The Box<dyn Error> material moves to the env-file
parser, where reading a file and parsing it genuinely mixes error
types. Smart pointers and the password validator are now bonus
chapters at the end.

Other changes:
- Strings intro gets the 30-second ownership rules and points at the
  new chapters.
- Downstream chapters (functions, vectors, hashmaps, tuples, result,
  conditionals) updated so ownership/borrowing read as already-taught
  instead of "later", and stale numeric chapter references are now
  name-based.
- Dropped two banned tics (the "lightbulb moment" line in functions and
  the "magpie" opener in the password validator).
- Appendix gains a short "why this course is built this way" page with
  the comparison table and a future-directions note.
- Renamed chapter dirs in both examples/ and solutions/, regenerated
  every main.rs, and updated the deliberately-broken list in
  check-examples.sh.

Note: renaming chapter directories changes the DB exercise_name stems,
so progress on the dev/restructure database resets. Production is on v1,
so it's unaffected.

Local CI is green: fmt, clippy, tests, check-examples,
check-solutions (75/75), typos, lychee.
Add a comment showing the format! one-liner and what it expands to
(a fresh String buffer via write_fmt), contrasted with the in-place
push_str version.
Rewrites submissions.exercise_name from the current main chapter names
to the new restructured layout (prefix shifts, the ownership split into
moves/borrowing, the ? operator move, and the sum_numbers_in_file
rename). Preserves all rows (no DELETE), idempotent, validated against a
scratch SQLite DB. Runs automatically at server startup via sqlx.
Mapped every key in analysis/course.db (58 participants, 1359 rows)
straight to its final restructured home, including the per-chapter step
renumberings from the content PRs that the snapshot predates. Exact-match
UPDATEs only, so it's collision-free and order-independent.

Validated against a copy of the snapshot: all 73 surviving distinct keys
land on real exercise files; the only unmapped rows (~180) are on
exercises that were removed (count_items, countdown, fallback,
frequent_words, char_classes, advisor, status, records, number_to_string)
and are left in place, not deleted.
The build context excludes .git, so build.rs couldn't read git info in
the image and the footer showed 'unknown'. build.rs now prefers
GIT_BRANCH / GIT_HASH from the environment (and Coolify's auto-injected
SOURCE_COMMIT for the short hash), falling back to git, then 'unknown'.
The Dockerfile declares these as build args and exports them as env
before the build. Verified the override lands in the binary.
@mre mre merged commit 5cbfa7b into main Jun 21, 2026
4 checks passed
@mre mre deleted the restructure-chapters branch June 21, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant