Crates.io | rahat3062_minigrep |
lib.rs | rahat3062_minigrep |
version | 0.1.3 |
source | src |
created_at | 2024-04-30 16:16:01.31042 |
updated_at | 2024-04-30 17:02:04.694582 |
description | A light-weight & minimal implementation of the grep cli app. |
homepage | |
repository | |
max_upload_size | |
id | 1225223 |
size | 16,977 |
rahat3062_minigrep
is a light-weight and minimal implementation of the grep command-line application. It is written in Rust and can be used both as a standalone application and as a library for other Rust programs.
install via:
cargo install rahat3062_minigrep && \
alias minigrep = rahat3062_minigrep
The binary crate provides a command-line interface to the grep functionality. You can use it to search for a string in a file. Here's how to run it:
minigrep <query> <filename> -s
Replace
If needed you can also take input from the stdin via pipelining:
history | minigrep cargo
The library crate provides a run
function that you can use to perform a grep search programmatically. Here's an example:
use rahat3062_minigrep::{Config, run};
let config = Config {
query: "my query".to_string(),
filename: Some("my_file.txt".to_string()),
sensitive: false,
};
let result = run(config);
In this example, run searches for "my query" in "my_file.txt" and returns the matching lines. The search is case-insensitive because sensitive is false.