A simple command-line text search tool built in Rust, following Chapter 12 of "The Rust Programming Language" book.
- Search for text patterns in files
- Case-sensitive and case-insensitive search through:
- Environment variable support (
IGNORE_CASE
) - Command-line flags (
-i
,-s
)
- Environment variable support (
git clone https://github.com/alexmatcov/minigrep.git
cd minigrep
cargo build --release
# change directory to the executable
cd src/target/release/
# run
./minigrep <query> <file_path> [flags]
where:
-
minigrep
is the executable binary found insrc/target/release/minigrep
; -
<query>
is the string pattern you're searching for; -
<file_path>
is the path to your document; -
optional:
[flags]
are the command-line arguments for:-s
case-sensitive search-i
case-insensitive search
NOTE: Default configuration (no set flags) is case-sensitive.
./minigrep to poem.txt
./minigrep rUst poem.txt -i
IGNORE_CASE=1 ./minigrep to poem.txt
The last example sets an environment variable to use the case-insensitive configuration.
In case of setting both the environment variable and the command-line argument the latter will take precedence.
cargo run -- <query> <file_path> [flags]
The project demonstrates key Rust concepts:
-
Data structures: Vectors and Strings
-
Error handling with Result<T, E>
-
Lifetime management
-
Using trais where appropriate
-
Unit testing
-
Command-line argument parsing
-
Environment variables