diff options
| author | bors <bors@rust-lang.org> | 2015-11-08 20:20:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-08 20:20:16 +0000 |
| commit | 9eb099daa4760901b5c3c094809fa6761849b8ad (patch) | |
| tree | 06744c88d9251940bdfb80e1502872f8fb569031 | |
| parent | e543815c85d4ec3ad4df30f4f9eb7933378ad47f (diff) | |
| parent | 0dd2c1c07dd2483618790262a2a661fee34c992f (diff) | |
| download | rust-9eb099daa4760901b5c3c094809fa6761849b8ad.tar.gz rust-9eb099daa4760901b5c3c094809fa6761849b8ad.zip | |
Auto merge of #29686 - jrburke:docs-error-handling-search-case, r=BurntSushi
In src/doc/trpl/error-handling.md, in this section: It mentions three steps, to "convert this to proper error handling", the last one being: 3. Handle the error in main. However, it is not shown. This pull request adds a code example showing how `main`'s call to `search` should use case analysis. I am still very much new to learning Rust, so this may not be idiomatic. Happy to make changes with guidance.
| -rw-r--r-- | src/doc/trpl/error-handling.md | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 68671cef707..52a4e7324ee 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -1838,6 +1838,22 @@ impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> impl From<String> for Box<Error + Send + Sync> ``` +Since `search` now returns a `Result<T, E>`, `main` should use case analysis +when calling `search`: + +```rust,ignore +... +match search(&data_file, &city) { + Ok(pops) => { + for pop in pops { + println!("{}, {}: {:?}", pop.city, pop.country, pop.count); + } + } + Err(err) => println!("{}", err) +} +... +``` + Now that we've seen how to do proper error handling with `Box<Error>`, let's try a different approach with our own custom error type. But first, let's take a quick break from error handling and add support for reading from `stdin`. |
