RepoRust_RustTextFinder.html
copyright © James Fawcett
Revised: 11/13/2025
Concept:
RustLogger is a facility for inserting time-date stamped string messages into the console and a text file
simultaneously. You can also select for console alone or text file alone.
Design:
Concept:
RustTextFinder is a tool for locating files containing text that matches a specified regular expression.
It uses the facilities of RustDirNav and RustCmdLine libraries, and std::fs and regex crates.
It can be used to:
-
Find all files in a directory subtree with text that matches a specified regular expression.
-
Find all files that have specified extensions (patterns).
-
List all directories and their files in some directory subtree.
It processes many hundreds of files and directories in a few seconds.
Design:
TextFinder implements the following methods and functions:
-
new() -> TextFinder
Create new TextFinder which holds a regex string.
-
find(&self, file_path: &str) -> bool
returns true if file content matches internal regex string.
-
regex(&mut self, re:&str)
Replace current regex string with re.
-
get_regex(&self) -> &str
Retrieve regex string.
RustTextFinder uses the services TextFinder, described above, and RustDirNav::DirNav<App>, where App must implement the trait
RustDirNav::DirEvent. For this application, DirNav is declared with the user-defined type TfAppl for its App parameter.
TfAppl holds an instance of TextFinder, a curr_dir string, and predicates hide and recurse. When DirNav<TfAppl>
encounters a file or directory it calls the DirEvent functions do_dir(&mut self, d:&str) and do_file(&mut self, f:&str).
TfAppl defines those functions to build output displays based on its command line parameters, as shown in Fig 2.
Operation:
When RustTextFinder is started, it:
-
creates an instance of CmdLineParser parser
-
uses that to evaluate the program's option parameters.
-
It then creates an instance of DirNav<TfAppl> dn, supplying it with the starting path, file patterns,
and recursion predicate, all extracted from parser.
-
calls dn.visit, starting at parser.abs_path(), converted
to a std::Path.
The results are shown in Fig 2.
Build:
Download and, in a command prompt, cargo build or cargo run.
Status:
Version 1.1.0
Tested on both Windows 10 and Ubuntu Linux