BuildOn - Step #4:   Executive & Display Pkgs

 

BuildOn Project - Executive and Display Packages

Figure 1. TextFinder Packages
Figure 2. TextFinder Structs
This Step creates Executive and Display packages and integrates them with CmdlnParser, TextSearher, DirNav, and Display packages. Figure 1 is a package diagram for Textfinder, showing how these parts fit together.
TextFinder Specification

TextFinder Specification:

  1. Identify all files in a directory subtree that match a pattern and contain a specified text.
  2. Specify root path, one or more file patterns (.h, .cpp, .cs, .rs, ...), and search text on command line.
  3. Specify options /s [true|false], /v [true|false], /H [true|false] /h [true|false] for recursive directory walk, verbose output header, Hidden dirs with no match, and help message, respectively.
  4. Display file name and path, without duplication of path name, e.g., organized by directory, for files containing the search text.
  5. Interesting extensions:
    • Replace text by regular expressions for both search text and file patterns.
    • Replace sequential file searches with parallel searches to improve performance and useability.
Executive uses CmdlnParser to access the program's starting path, file patterns, search text, and options. Executive configures the CLPparser instance for TextFinder's Finder operations by defining default values of program attributes not already defined on the command line. It then creates a member instance of DirNav, providing it access to TextSearch::Finder as a generic parameter. DirNav creates an instance of TextSearch's Finder and provides access to it via a member function DirNav<App>::getApp(). This may be used to configure Finder before starting a search. It may also be used to collect results that are specific to DirNav, e.g., the number of files and directories processed. Executive uses getApp() to configure it with search text.
 

Step #4 - Build Executive Package

In this step we will create the Executive package and integrate it with CmdlnParser, DirNav, and TextSearch. Note that each of the packages defines a user-defined type, e.g., struct, as shown in Figure 2.. Executive:
  1. Creates a member instance of CLParser and configures it for TextFinder operations by defining default values for program attributes not already defined on the command line.
  2. Creates a member instance of DirNav and passes it properties from Executive::CLParser.
  3. DirNav creates a member instance of TextSearch's Finder.
  4. Executive configures Finder with search text via DirNav<T>::get_app().
The Display package implements struct GenOut that is responsible for rendering program data into useful information. It:
  1. Has two member functions:
    fn dir(&mut self, dirname: &str)
    fn result(&mut self, rsl: (flnm:&str, found:bool))

Notes:

The same notes used for Step #2 apply here.
 

Step #4 References

The table below provides references relevant for Step #2 : DirNav. The first links refer to specific regions of the Rust Story, from this site. Other links go to Rust documentation. You can look at the Rust Story by selecting the Rust Story link in the menu in the left panel.
 

Table 2. - Step #4 References

Topic Description Link
Generics Generics in Rust are very similar to those in C# and Java, and simpler than C++ templates. They are code generators often do little more than substitute a specific type for a generic parameter. Rust generics are often constrained with traits, as discussed above. Rust Story Generics
Rust Bites Generics and Traits
The Rust Book
Ownership Rusts ownership rules: There is only one owner for any resource. Owners deallocate their resources when they go out of scope. Ownership can be transferred with a Move or borrowed with a reference. References don't own resources, they just borrow them, and so never deallocate. Rust ownership does not support simultaneously aliasing and mutation. Rust Bites Ownership
Rust Story Ownership
By Example
Rust Book
Rust Nomicon
Strings Rust std strings come in two flavors: String and str, representing string objects and literal strings. Each contains utf-8 characters. The Rust library path also provides PathBuf, similar to String, and Path, similar to &str, but uses the encoding for paths provided by the current platform, e.g., Windows, Linux, or macOS. std::String
std::str
std::path
std::path::PathBuf std::path::Path
Rust by Example
struct Rust structs serve the same role as classes do in C++ and C#. Struct methods are defined inside impl StructName {} blocks. Rust Story structs
std::Stuct
keyword impl
File System Rust has a well engineered facility for accessing files and directories.
Some key types in std::fs are: DirEntry, File, OpenOptions, ReadDir, ...
Rust story File System
std::fs
 
You don't need to use all of the references in the right-most column. Just look at each quickly and use the one(s) that work(s) best for you.
 
 toggle menu