Rust closure capture and Fn traits

F-FNTRAIT-V4-2medium

Keep one running total

The registration batch first welcomes every supplied visitor and reports the batch count. Its payment pass prints a running admission total after every amount, then reconciles that total with the caller’s final report. Its badge pass reuses one callback for every name; badge text must remain available for the next call instead of being consumed by the first visitor.

What needs to change

Repair the closure in main so the final total matches the running total.

Reproduce

  1. Build and run the two-sale sample with rustc, then compare the running lines with the last line.

Acceptance criteria

Your review marks · Saved in this browser. Test acceptance is tracked separately.

Notes

The file contains its use declaration, read_rows and main. main keeps the total in a u32.

Input: sale and an amount on each line.

Supplied batches contain at most 1,000 well-formed sale rows. Amounts are nonnegative base-ten integers representable as u32, and their sum fits u32. These are input assumptions, not reader validation.

Sign in to open this exercise

The ticket brief is public. Sign in to access the exercise. Paid exercises require Pro.

Sign in