Rust Bus Agency — Rust

Build bus manifests from WhatsApp lists with real Cargo: String, UTF-8, Vec, HashMap, iterators. 15 levels, played right in the browser with nothing to install.

What you learn in this game

Mr. Yanto spent ten years as a conductor on tour buses to Jogja and Bali. Now he runs Agen Bus Wuni from his front room at the mouth of Wuni Lane. Every group in the village books its bus through him, and the bus company wants a passenger manifest before the bus leaves. The passenger lists come from WhatsApp groups, typed by many people on many phones. Mr. Yanto writes a small Rust program, manifes, to read them. Rust has two kinds of text: String, which is owned and can grow, and &str, a borrow for reading text stored somewhere else.

A WhatsApp group is the village notice board: a list is pinned there, and everyone copies it and adds their own name. A program can read that pasted text through its standard input (stdin). io::stdin().lines() gives one line per round, wrapped in a Result because reading can fail.

Reading typed input usually reuses one box: read_line(&mut baris) fills baris, then clear() empties it for the next line. The box saves memory, but anything that borrows what it holds stops being valid the moment the box is emptied.

A computer keeps text as a run of bytes. UTF-8, the way Rust keeps text, uses one byte for the letters a to z, and two to four bytes for other letters: é, ñ, Arabic letters, Javanese script. So a text's length in bytes is not always its number of letters.

A HashSet is a collection with no twins, like a guest book that refuses a name already written in it. insert puts a value in and answers whether the value was new. retain filters a Vec in place: the closure is called for each item, and the items it answers false for are dropped.

A HashMap keeps pairs of keys and values, like a board of seat numbers: look up the name, get the number. Looking up a key that is not there is normal, and Rust has two ways to look up that treat it differently.