From 901aa3d7884b7598dfecd5de755b9917525ab50a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 30 Dec 2016 12:43:26 -0500 Subject: [PATCH] Fix code examples and output --- src/ch09-02-recoverable-errors-with-result.md | 2 +- src/ch12-04-testing-the-librarys-functionality.md | 2 +- src/ch12-06-writing-to-stderr-instead-of-stdout.md | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 523ee83..e301310 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -562,7 +562,7 @@ error message. /Carol --> When we compile this, we get the following error message: -```bash +```text error[E0308]: mismatched types --> | diff --git a/src/ch12-04-testing-the-librarys-functionality.md b/src/ch12-04-testing-the-librarys-functionality.md index 9fb46d7..1eda846 100644 --- a/src/ch12-04-testing-the-librarys-functionality.md +++ b/src/ch12-04-testing-the-librarys-functionality.md @@ -191,7 +191,7 @@ vector: Filename: src/lib.rs -```rust,ignore +```rust fn grep<'a>(search: &str, contents: &'a str) -> Vec<&'a str> { let mut results = Vec::new(); diff --git a/src/ch12-06-writing-to-stderr-instead-of-stdout.md b/src/ch12-06-writing-to-stderr-instead-of-stdout.md index 8fff0a2..e12d541 100644 --- a/src/ch12-06-writing-to-stderr-instead-of-stdout.md +++ b/src/ch12-06-writing-to-stderr-instead-of-stdout.md @@ -19,7 +19,7 @@ The `>` syntax tells the shell to write the contents of standard out to running we'll see our error message: ```text -Application error: No search string or filename found +Problem parsing arguments: not enough arguments ``` We'd like this to be printed to the screen instead, and only have the output @@ -34,19 +34,25 @@ extern crate greprs; use std::env; use std::process; +use std::io::prelude::*; use greprs::Config; fn main() { + let mut stderr = std::io::stderr(); let args: Vec = env::args().collect(); let config = Config::new(&args).unwrap_or_else(|err| { - println!("Problem parsing arguments: {}", err); + writeln!( + &mut stderr, + "Problem parsing arguments: {}", + err + ).expect("Could not write to stderr"); + process::exit(1); }); if let Err(e) = greprs::run(config) { - let mut stderr = std::io::stderr(); writeln!( &mut stderr, @@ -82,7 +88,7 @@ redirecting `stdout` with `>`: ```text $ cargo run > output.txt -Application error: No search string or filename found +Problem parsing arguments: not enough arguments ``` Now we see our error on the screen, but `output.txt` contains nothing. If we