expression
Report work without inventing a percentage
Some input streams have no known length. Report counts rather than inventing a percentage or remaining duration. A known zero total is a separate empty-work case, not a division by zero. Fixture: Expected stdout (not executed): 3 records processed empty workload 3/5 records Expected stderr: (empty) Expected exit: 0 Common mistake: Displaying 100% just because no further input has arrived yet.
Formal Syntax & Structure
rust syntaxrust
match total { Some(n) => ..., None => ... }Working Example
Example Snippetrust
fn main() { fn report(done: u64, total: Option<u64>) -> String { match total { Some(0) if done == 0 => "empty workload".into(), Some(n) if done <= n => format!("{done}/{n} records"), Some(_) => "inconsistent count".into(), None => format!("{done} records processed"), } } println!("{}", report(3, None)); println!("{}", report(0, Some(0))); println!("{}", report(3, Some(5)));}