From 9d2ea42fc49407f1cc14b95370bc3da32b8ee130 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Fri, 27 Sep 2024 08:39:53 -0400 Subject: [PATCH] Fix thiserror slide (#2380) Fixes #2379. This has `compile_fail` because `thiserror` isn't available from within `mdbook test`. --- src/error-handling/thiserror.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error-handling/thiserror.md b/src/error-handling/thiserror.md index aa5925c6..adbce001 100644 --- a/src/error-handling/thiserror.md +++ b/src/error-handling/thiserror.md @@ -10,10 +10,10 @@ assist in implementing `From`, `Display`, and the `Error` trait. ```rust,editable,compile_fail use std::fs; -use std::io::Read; +use std::io::{self, Read}; use thiserror::Error; -#[derive(Error)] +#[derive(Debug, Error)] enum ReadUsernameError { #[error("I/O error: {0}")] IoError(#[from] io::Error), @@ -23,7 +23,7 @@ enum ReadUsernameError { fn read_username(path: &str) -> Result { let mut username = String::with_capacity(100); - File::open(path)?.read_to_string(&mut username)?; + fs::File::open(path)?.read_to_string(&mut username)?; if username.is_empty() { return Err(ReadUsernameError::EmptyUsername(String::from(path))); }