Skip to content

Commit 3042fba

Browse files
committed
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 <[email protected]>
1 parent f55ac69 commit 3042fba

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/doc/book/error-handling.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ story. The other half is *using* the `find` function we've written. Let's try
166166
to use it to find the extension in a file name.
167167

168168
```rust
169-
# fn find(_: &str, _: char) -> Option<usize> { None }
169+
# fn find(haystack: &str, needle: char) -> Option<usize> { haystack.find(needle) }
170170
fn main() {
171171
let file_name = "foobar.rs";
172172
match find(file_name, '.') {
@@ -223,7 +223,7 @@ Getting the extension of a file name is a pretty common operation, so it makes
223223
sense to put it into a function:
224224

225225
```rust
226-
# fn find(_: &str, _: char) -> Option<usize> { None }
226+
# fn find(haystack: &str, needle: char) -> Option<usize> { haystack.find(needle) }
227227
// Returns the extension of the given file name, where the extension is defined
228228
// as all characters following the first `.`.
229229
// 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
272272
to get rid of the case analysis:
273273

274274
```rust
275-
# fn find(_: &str, _: char) -> Option<usize> { None }
275+
# fn find(haystack: &str, needle: char) -> Option<usize> { haystack.find(needle) }
276276
// Returns the extension of the given file name, where the extension is defined
277277
// as all characters following the first `.`.
278278
// If `file_name` has no `.`, then `None` is returned.

0 commit comments

Comments
 (0)