[Rust Guide]12.8. Writing Error Messages to Standard Error This article explains how to modify a Rust command-line grep program to separate error messages from standard output by using the `eprintln!` macro instead of `println!`. The key advantage is that when normal output is redirected to a file using `cargo run > output.txt`, error messages will still appear on the screen rather than being written to the file. The change only requires modifying `main.rs` to use `eprintln!` for all error handling, leaving `lib.rs` unchanged. 12.8.0 Before We Begin Chapter 12 builds a sample project: a command-line program. The program is grep Global Regular Expression Print , a tool for global regular-expression searching and output. Its function is to search for specified text in a specified file . This project is divided into these steps: - Receiving command-line arguments - Reading files - Refactoring: improving modules and error handling - Using TDD test-driven development to develop library functionality - Using environment variables Writing error messages to standard error instead of standard output this article If you find this helpful, please like, bookmark, and follow. To keep learning along, follow this series. 12.8.1 Review Here is all the code written up to the previous article. lib.rs : use std::error::Error; use std::fs; pub struct Config { pub query: String, pub filename: String, pub case sensitive: bool, } impl Config { pub fn new args: & String - Result