Revision · Project 1 — logwise
Project 1 built logwise, a small log-analysis CLI, and used it to make Rust’s core ideas concrete: ownership, honest errors, and iterators. Here’s what to carry forward.
What this part covered
Section titled “What this part covered”- Ownership and borrowing — one
Stringowns the file bytes;.lines()hands out&strborrows that copy nothing, and the borrow checker guarantees no borrow outlives its buffer. - Modeling data with types — a
Levelenum ordered by severity and aLogLinestruct make illegal states unrepresentable;matchis exhaustive, so a missing case is a compile error. - Arg parsing with clap — a derived argument struct turns the command line into typed fields, so the CLI’s inputs are validated before the pipeline ever runs.
- Honest errors —
Optionmodels absence,Resultmodels failure, and?propagates them; a customthiserrorenum (LogError/ParseError) names each failure and chains its cause instead of pyramidingmatcharms. - Modules —
mod,pub, anduse crate::…split the crate intoparser,analyze,cli, anderror, each testable on its own. - Iterators —
filter,map, andfoldbuild the summary histogram in one allocation-free pass the compiler fuses into a hand-written-speed loop. - Testing and shipping —
#[cfg(test)]unit tests live next to the code, atests/integration test drives the real binary end to end, andcargo installturns it into a CLI you actually use.
The takeaway
Section titled “The takeaway”Every feature forced a Rust idea into the open: reading a file forced the ownership question, parsing forced Result, summarizing forced iterators. That’s the throughline for the whole book — you learn each concept the moment a real project needs it, and the next project, kvlite, builds straight on this foundation, where those same rules buy you fearless concurrency.