From 7e59a106a1d7d5b3e69961b14bf18c0b646d7057 Mon Sep 17 00:00:00 2001 From: Alexandre Senges Date: Mon, 14 Aug 2023 16:58:18 +0200 Subject: [PATCH] As done in Rust book https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html --- src/error-handling/dynamic-errors.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/error-handling/dynamic-errors.md b/src/error-handling/dynamic-errors.md index 14074131..cf96c214 100644 --- a/src/error-handling/dynamic-errors.md +++ b/src/error-handling/dynamic-errors.md @@ -7,12 +7,13 @@ all the different possibilities. `std::error::Error` makes this easy. use std::fs; use std::io::Read; use thiserror::Error; +use std::error; #[derive(Clone, Debug, Eq, Error, PartialEq)] #[error("Found no username in {0}")] struct EmptyUsernameError(String); -fn read_username(path: &str) -> Result> { +fn read_username(path: &str) -> Result> { let mut username = String::new(); fs::File::open(path)?.read_to_string(&mut username)?; if username.is_empty() {