← All bricks

Rust · Beginner

Rust: Build a Log Triage Tool

Learn Rust by building triage, a real log-analysis CLI: ownership and borrowing, structs and enums, Result and the ? operator, iterators, HashMap, generics, traits, lifetimes, modules and tests — one small step at a time, with every compiler message read and understood.

Hello-world programs teach you syntax and nothing else. This course teaches Rust by building a tool you could genuinely use tomorrow: triage, a command-line log analyzer that answers the first questions of any incident — how many errors, which ones, since when, and what was slow. Every concept arrives exactly when the program needs it: ownership when a loop eats your Vec, enums when strings stop being enough, lifetimes when the compiler genuinely cannot guess. Twice we walk straight into a compiler error on purpose, read it line by line, and fix it — because reading rustc's advice is half of writing Rust.

What you'll build

  • Read and write ownership: moves, borrows, and when to clone
  • Model data with structs and enums, and take them apart with match
  • Handle failure with Option, Result, ? and your own error type
  • Process data with iterators, closures, Vec and HashMap
  • Write generic functions with trait bounds and implement std traits
  • Understand lifetimes where elision ends, split code into modules, and test it

Contents

  1. A new Cargo project
  2. Hello, world — for a minute
  3. Run it
  4. Read the arguments
  5. Arguments, seen by the program
  6. Pick out the file path
  7. What happens with no argument
  8. The sample log
  9. Read the whole file
  10. unwrap on a missing file
  11. Match on the Result
  12. A clean failure
  13. Extract run and meet ?
  14. Same behaviour, tidier shape
  15. Count the lines
  16. Forty-five lines of afternoon
  17. Split the first line
  18. The first entry, dissected
  19. A shape for one entry
  20. Parse one line
  21. Show what we parsed
  22. One line, structured
  23. Feed it junk
  24. Junk becomes None
  25. A type for levels
  26. From text to Level
  27. The entry carries a Level
  28. Typed levels, silent failures
  29. if let in main
  30. Name what can go wrong
  31. Errors that explain themselves
  32. Parse returns Result
  33. Errors with reasons
  34. Collect every entry
  35. The whole file, parsed
  36. Count the errors
  37. borrow of moved value
  38. Borrow, don't move
  39. Errors counted
  40. Count every level at once
  41. Trait bounds were not satisfied
  42. Derive Eq and Hash
  43. Levels tallied
  44. Group the error messages
  45. Rank the top offenders
  46. Top offenders
  47. One generic counter
  48. Same numbers, less code
  49. FromStr, the standard way
  50. Display for Level
  51. A tidy summary
  52. Which service is failing
  53. Counts by service
  54. When did it start
  55. First seen
  56. A parser module
  57. A stats module
  58. Same tool, clean layout
  59. Two reports, two functions
  60. Dispatch on a command
  61. Subcommands and usage
  62. Reading durations
  63. The slow command
  64. Slow requests
  65. Test the parser
  66. cargo test
  67. Test the stats
  68. The whole suite
  69. The release build