| Crates.io | book |
| lib.rs | book |
| version | 0.2.0 |
| created_at | 2025-07-17 03:47:59.630052+00 |
| updated_at | 2025-11-03 05:18:10.128144+00 |
| description | A fun game where you guess what number the computer has chosen. |
| homepage | https://www.dart.xin |
| repository | https://github.com/zwdart/book |
| max_upload_size | |
| id | 1757042 |
| size | 12,990 |
Below is a professional and detailed README.md file for your Rust crate. It includes an overview of the functionality, installation instructions, usage examples, and additional notes.
A flexible and efficient Rust library for searching text within files. Supports multiple search modes (substring and regex), optional case-insensitive searches, and writing results to an output file or printing them to the console.
If you want to use this crate in your project, add it to your Cargo.toml:
[dependencies]
search = { path = "path_to_search_crate" }
Alternatively, if the crate is published to crates.io, you can include it as:
[dependencies]
search = "0.2.0"
The crate provides a command-line interface for performing searches. Below are examples of how to use it.
Perform a case-sensitive substring search and print results to the console:
cargo run -- search "Error" "./large_log_file.txt"
Perform a case-insensitive regex search and write results to an output file:
cargo run -- regex "error\d+" "./large_log_file.txt" "./output.txt" --ignore-case
If insufficient arguments are provided, the program will display a usage message:
Usage: cargo run -- <mode> <search_string> <file_path> [output_file] [--ignore-case]
You can also use the crate programmatically in your Rust code. Here's an example:
use search::search_in_file;
fn main() -> std::io::Result<()> {
// Perform a case-insensitive regex search and print results to the console
search_in_file(
"./large_log_file.txt", // File path
"error\\d+", // Query (regex pattern)
None, // Output file (None means print to console)
true, // Ignore case
true // Treat query as regex
)
}
The program accepts the following arguments:
| Argument | Description |
|---|---|
<mode> |
The search mode (search for substring, regex for regular expressions). |
<search_string> |
The string or regex pattern to search for in the file. |
<file_path> |
The path to the file to search. |
[output_file] |
(Optional) The path to the file where results will be written. |
[--ignore-case] |
(Optional) If provided, the search will ignore case. |
Search for the word "Error" in large_log_file.txt and print results to the console:
cargo run -- search "Error" "./large_log_file.txt"
Search for lines matching the regex pattern "error\d+" in large_log_file.txt, ignoring case, and write results to output.txt:
cargo run -- regex "error\d+" "./large_log_file.txt" "./output.txt" --ignore-case
If the regex pattern is invalid, the program will notify you:
cargo run -- regex "[" "./large_log_file.txt"
Invalid regex pattern '['
The program gracefully handles errors such as:
Example error messages:
Error: No such file or directory (os error 2)
Invalid regex pattern '['
regex crate for regex support.Contributions are welcome! To contribute:
git checkout -b feature/your-feature).git commit -am 'Add feature').git push origin feature/your-feature).This project is licensed under the MIT License. See the LICENSE file for details.
This README.md provides a comprehensive overview of your crate, making it easy for users to understand its functionality and integrate it into their projects. Let me know if you'd like to customize it further!