Skip to content

Commit 9d2ea42

Browse files
authored
Fix thiserror slide (#2380)
Fixes #2379. This has `compile_fail` because `thiserror` isn't available from within `mdbook test`.
1 parent 2713ea3 commit 9d2ea42

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/error-handling/thiserror.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ assist in implementing `From<T>`, `Display`, and the `Error` trait.
1010

1111
```rust,editable,compile_fail
1212
use std::fs;
13-
use std::io::Read;
13+
use std::io::{self, Read};
1414
use thiserror::Error;
1515
16-
#[derive(Error)]
16+
#[derive(Debug, Error)]
1717
enum ReadUsernameError {
1818
#[error("I/O error: {0}")]
1919
IoError(#[from] io::Error),
@@ -23,7 +23,7 @@ enum ReadUsernameError {
2323
2424
fn read_username(path: &str) -> Result<String, ReadUsernameError> {
2525
let mut username = String::with_capacity(100);
26-
File::open(path)?.read_to_string(&mut username)?;
26+
fs::File::open(path)?.read_to_string(&mut username)?;
2727
if username.is_empty() {
2828
return Err(ReadUsernameError::EmptyUsername(String::from(path)));
2929
}

0 commit comments

Comments
 (0)