Skip to content

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.

  • Ownership and borrowing — one String owns the file bytes; .lines() hands out &str borrows that copy nothing, and the borrow checker guarantees no borrow outlives its buffer.
  • Modeling data with types — a Level enum ordered by severity and a LogLine struct make illegal states unrepresentable; match is 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 errorsOption models absence, Result models failure, and ? propagates them; a custom thiserror enum (LogError/ParseError) names each failure and chains its cause instead of pyramiding match arms.
  • Modulesmod, pub, and use crate::… split the crate into parser, analyze, cli, and error, each testable on its own.
  • Iteratorsfilter, map, and fold build 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, a tests/ integration test drives the real binary end to end, and cargo install turns it into a CLI you actually use.

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.