Minimal grep
written in Rust! Follows chapter 10 of The Rust Book.
cargo run <word> <file>
- Guideline for splitting the separate concerns (see more here) of a binary program when
main
starts getting large:- Split your program into a main.rs and a lib.rs and move your program’s logic to lib.rs.
- As long as your command line parsing logic is small, it can remain in main.rs.
- When the command line parsing logic starts getting complicated, extract it from main.rs and move it to lib.rs.
- Call to
panic!
is more appropriate for a programming problem than a usage problem. - Test-driven development (TDD) process:
- Write a test that fails and run it to make sure it fails for the reason you expect.
- Write or modify just enough code to make the new test pass.
- Refactor the code you just added or changed and make sure the tests continue to pass.
- Repeat from step 1!