Fix code examples and output

This commit is contained in:
Carol (Nichols || Goulding) 2016-12-30 12:43:26 -05:00
parent 1a7c4764e7
commit 901aa3d788
3 changed files with 12 additions and 6 deletions

View File

@ -562,7 +562,7 @@ error message. /Carol -->
When we compile this, we get the following error message:
```bash
```text
error[E0308]: mismatched types
-->
|

View File

@ -191,7 +191,7 @@ vector:
<span class="filename">Filename: src/lib.rs</span>
```rust,ignore
```rust
fn grep<'a>(search: &str, contents: &'a str) -> Vec<&'a str> {
let mut results = Vec::new();

View File

@ -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<String> = 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