diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-08-14 20:29:51 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-14 20:29:51 +0300 |
| commit | 5766b4257248a73b6cbe85b13482f09c9aa2ccdd (patch) | |
| tree | d38bad68f7ea287ff281f160aa9b5b064f37e656 | |
| parent | 15f66ad326555011abaccaa2d4a758833cc7d2a1 (diff) | |
| parent | 3042fba44c82a42e427b9e301f3d3f3412e747dc (diff) | |
| download | rust-5766b4257248a73b6cbe85b13482f09c9aa2ccdd.tar.gz rust-5766b4257248a73b6cbe85b13482f09c9aa2ccdd.zip | |
Rollup merge of #35620 - cvubrugier:master, r=Manishearth
book: fix the hidden find() functions in error-handling.md The hidden find() functions always returns None. Consequently, one of the examples using find() prints "No file extension found" instead of "File extension: rs" which is the expected output. This patch fixes the issue by implementing find() with std::str::find(). Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
| -rw-r--r-- | src/doc/book/error-handling.md | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 544f837d69b..6e13b464e4c 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -166,7 +166,7 @@ story. The other half is *using* the `find` function we've written. Let's try to use it to find the extension in a file name. ```rust -# fn find(_: &str, _: char) -> Option<usize> { None } +# fn find(haystack: &str, needle: char) -> Option<usize> { haystack.find(needle) } fn main() { let file_name = "foobar.rs"; match find(file_name, '.') { @@ -223,7 +223,7 @@ Getting the extension of a file name is a pretty common operation, so it makes sense to put it into a function: ```rust -# fn find(_: &str, _: char) -> Option<usize> { None } +# fn find(haystack: &str, needle: char) -> Option<usize> { haystack.find(needle) } // Returns the extension of the given file name, where the extension is defined // as all characters following the first `.`. // If `file_name` has no `.`, then `None` is returned. @@ -272,7 +272,7 @@ Armed with our new combinator, we can rewrite our `extension_explicit` method to get rid of the case analysis: ```rust -# fn find(_: &str, _: char) -> Option<usize> { None } +# fn find(haystack: &str, needle: char) -> Option<usize> { haystack.find(needle) } // Returns the extension of the given file name, where the extension is defined // as all characters following the first `.`. // If `file_name` has no `.`, then `None` is returned. |
