An I/O Project: Building a Command Line Program

    Rust’s speed, safety, single binary output, and cross-platform support make it an ideal language for creating command line tools, so for our project, we’ll make our own version of the classic command line tool (globally search a regular expression and print). In the simplest use case, grep searches a specified file for a specified string. To do so, grep takes as its arguments a filename and a string. Then it reads the file, finds lines in that file that contain the string argument, and prints those lines.

    One Rust community member, Andrew Gallant, has already created a fully featured, very fast version of grep, called . By comparison, our version of grep will be fairly simple, but this chapter will give you some of the background knowledge you need to understand a real-world project such as ripgrep.

    • Organizing code (using what you learned about modules in )
    • Handling errors (Chapter 9)
    • Writing tests ()

    We’ll also briefly introduce closures, iterators, and trait objects, which Chapters 13 and will cover in detail.