minigrep is a beginner-friendly command-line tool written in Rust, inspired by the Unix grep utility. It allows you to search for lines containing a query string within a text file. This project shows file I/O, error handling, and ownership in Rust.
- Search for exact matches of a query string in a file.
- Case-insensitive search option using an environment variable.
- Graceful error handling with user-friendly messages.
- Demonstrates idiomatic Rust patterns such as
Result,Option,struct, and module organization.
-
Ensure Rust and Cargo are installed
You can install Rust using rustup:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone https://github.com/jolah1/minigrep.git cd minigrepcargo build --release
cargo run -- body poem.txt
Set the CASE_INSENSITIVE environment variable before running:
``bash CASE_INSENSITIVE=1 cargo run -- "to" poem.txt
Or on Windows (PowerShell): ```bash $env:CASE_INSENSITIVE=1 cargo run -- "to" poem.txtcargo testOwnership and borrowing
-
String slices and lifetimes
-
Structs and enums
-
File reading with std::fs
-
Pattern matching with match
-
Error propagation using Result
-
Unit testing with #[test]
Contributions are welcome! Please fork the repository and open a pull request. Thank you!