Project 1: A Command-Line grep Clone (greprs)

A simple command-line tool that searches for a pattern in a file and prints the lines that contain it.

Quick Reference

Attribute Value
Primary Language Rust
Alternative Languages C, Go
Difficulty Level 1: Beginner
Time Estimate Weekend
Knowledge Area CLI Tools / File I/O
Tooling cargo
Prerequisites None, this is a great place to start.

What You Will Build

A simple command-line tool that searches for a pattern in a file and prints the lines that contain it.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Parsing command-line arguments → maps to using std::env::args and basic ownership
  • Reading a file line by line → maps to using std::fs and handling Result for I/O errors
  • Handling configuration (e.g., case-insensitivity) → maps to using structs for configuration
  • Writing clean, testable logic → maps to separating your main function from your library logic

Key Concepts

  • Cargo and Crates: “The Rust Programming Language” Ch. 1 & 7
  • Structs and Enums: “The Rust Programming Language” Ch. 5
  • Error Handling with Result: “The Rust Programming Language” Ch. 9
  • Standard Library I/O: “The Rust Programming Language” Ch. 12

Real-World Outcome

$ cat poem.txt
I'm nobody! Who are you?
Are you nobody, too?

$ cargo run -- nobody poem.txt
I'm nobody! Who are you?
Are you nobody, too?

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_RUST_FROM_FIRST_PRINCIPLES.md
  • “The Rust Programming Language” by Klabnik & Nichols