diff --git a/src/error/multiple_error_types/boxing_errors.md b/src/error/multiple_error_types/boxing_errors.md index c5f43a9332..aceafd6dd2 100644 --- a/src/error/multiple_error_types/boxing_errors.md +++ b/src/error/multiple_error_types/boxing_errors.md @@ -11,7 +11,6 @@ via [`From`][from]. ```rust,editable use std::error; use std::fmt; -use std::num::ParseIntError; // Change the alias to `Box`. type Result = std::result::Result>; @@ -38,15 +37,17 @@ impl error::Error for EmptyVec { fn double_first(vec: Vec<&str>) -> Result { vec.first() - .ok_or_else(|| EmptyVec.into()) // Converts to Box - .and_then(|s| s.parse::() - .map_err(|e| e.into()) // Converts to Box - .map(|i| 2 * i)) + .ok_or_else(|| EmptyVec.into()) // Converts to Box + .and_then(|s| { + s.parse::() + .map_err(|e| e.into()) // Converts to Box + .map(|i| 2 * i) + }) } fn print(result: Result) { match result { - Ok(n) => println!("The first doubled is {}", n), + Ok(n) => println!("The first doubled is {}", n), Err(e) => println!("Error: {}", e), } } diff --git a/src/error/multiple_error_types/define_error_type.md b/src/error/multiple_error_types/define_error_type.md index fdd9e80b00..b7187d0d01 100644 --- a/src/error/multiple_error_types/define_error_type.md +++ b/src/error/multiple_error_types/define_error_type.md @@ -18,14 +18,13 @@ Rust allows us to define our own error types. In general, a "good" error type: ```rust,editable use std::error; use std::fmt; -use std::num::ParseIntError; type Result = std::result::Result; -#[derive(Debug, Clone)] // Define our error types. These may be customized for our error handling cases. // Now we will be able to write our own errors, defer to an underlying error // implementation, or do something in between. +#[derive(Debug, Clone)] struct DoubleError; // Generation of an error is completely separate from how it is displayed. @@ -53,17 +52,19 @@ impl error::Error for DoubleError { fn double_first(vec: Vec<&str>) -> Result { vec.first() - // Change the error to our new type. - .ok_or(DoubleError) - .and_then(|s| s.parse::() - // Update to the new error type here also. - .map_err(|_| DoubleError) - .map(|i| 2 * i)) + // Change the error to our new type. + .ok_or(DoubleError) + .and_then(|s| { + s.parse::() + // Update to the new error type here also. + .map_err(|_| DoubleError) + .map(|i| 2 * i) + }) } fn print(result: Result) { match result { - Ok(n) => println!("The first doubled is {}", n), + Ok(n) => println!("The first doubled is {}", n), Err(e) => println!("Error: {}", e), } }