minigrep
A small command-line clone of grep written while working through the Rust book. It loads a file, looks for a query string, and prints every matching line. The exercise focuses on learning how to structure a medium-sized Rust binary crate, handle errors, and write unit tests.
Usage
query– the text to search for.path– path to the file that should be scanned (for examplepoem.txt).- By default the search is case-sensitive. Set
CASE_INSENSITIVE=1to switch to case-insensitive search.
Examples:
CASE_INSENSITIVE=1
Both commands return the lines containing the query. When the query is missing or the file cannot be read, the program exits with a non-zero status and prints a helpful message.
Development notes
- Argument parsing and configuration live in
src/lib.rs, keepingsrc/main.rsvery small. - The library exposes a
searchand asearch_case_insensitivefunction so logic can be unit-tested (cargo test). - The project sticks to the Rust standard library; no external crates are required.
Testing
Run unit tests with:
This covers both the case-sensitive and case-insensitive search helpers.