Skip to content

Commit

Permalink
book: fix the hidden find() functions in error-handling.md
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cvubrugier committed Aug 12, 2016
1 parent f55ac69 commit 3042fba
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, '.') {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3042fba

Please sign in to comment.