Rust Shallot Shed — Rust

Total a farmers' group's money from messy CSV with real Cargo: parse, i64, overflow, Result, tests. 14 levels, right in the browser.

What you learn in this game

Kelompok Tani Sido Makmur, a farmers' group, sells its members' shallots together to a trader. Last year, at the closing meeting, the sum formula in the shared sheet skipped one cell that had been typed as text, 1.250.000, and Grandma Marni was paid 1,250,000 rupiah short. This year Ms. Tami, the group's secretary, writes rekap: a small Rust program that reads the sheet as a CSV file and prints what each member is owed. It has to read numbers the way people type them, and it must not stay quiet when one cannot be read.

A Result is an answer that can succeed or fail: Ok(value) or Err(reason). Rust does not let the reason vanish on its own. The programmer chooses: stop, use a stand-in value, or handle the failure.

A HashMap stores pairs of a key and a value, like a cash book with one page per member. A page is found by name, not by its number.

? works on an Option too. In a function that returns an Option, value? gives what is inside Some, or returns None from that function straight away.

An enum is a type whose value is always one of a list of variants. A match on an enum must handle every variant. If one is missing, rustc refuses (E0004) and names the variant left out.

A program often meets more than one kind of error. An error enum gathers them in one type, one variant per kind, so its caller knows what happened.