diff --git a/exercises/13_error_handling/errors6.rs b/exercises/13_error_handling/errors6.rs index b1995e036a..73055c794c 100644 --- a/exercises/13_error_handling/errors6.rs +++ b/exercises/13_error_handling/errors6.rs @@ -19,15 +19,6 @@ enum ParsePosNonzeroError { ParseInt(ParseIntError), } -impl ParsePosNonzeroError { - fn from_creation(err: CreationError) -> Self { - Self::Creation(err) - } - - // TODO: Add another error conversion function here. - // fn from_parse_int(???) -> Self { ??? } -} - #[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); @@ -44,7 +35,7 @@ impl PositiveNonzeroInteger { // TODO: change this to return an appropriate error instead of panicking // when `parse()` returns an error. let x: i64 = s.parse().unwrap(); - Self::new(x).map_err(ParsePosNonzeroError::from_creation) + Self::new(x).map_err(ParsePosNonzeroError::Creation) } } diff --git a/solutions/13_error_handling/errors6.rs b/solutions/13_error_handling/errors6.rs index ce18073afb..cb49fc5ddb 100644 --- a/solutions/13_error_handling/errors6.rs +++ b/solutions/13_error_handling/errors6.rs @@ -19,16 +19,6 @@ enum ParsePosNonzeroError { ParseInt(ParseIntError), } -impl ParsePosNonzeroError { - fn from_creation(err: CreationError) -> Self { - Self::Creation(err) - } - - fn from_parse_int(err: ParseIntError) -> Self { - Self::ParseInt(err) - } -} - // As an alternative solution, implementing the `From` trait allows for the // automatic conversion from a `ParseIntError` into a `ParsePosNonzeroError` // using the `?` operator, without the need to call `map_err`. @@ -59,9 +49,9 @@ impl PositiveNonzeroInteger { fn parse(s: &str) -> Result { // Return an appropriate error instead of panicking when `parse()` // returns an error. - let x: i64 = s.parse().map_err(ParsePosNonzeroError::from_parse_int)?; - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Self::new(x).map_err(ParsePosNonzeroError::from_creation) + let x: i64 = s.parse().map_err(ParsePosNonzeroError::ParseInt)?; + // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + Self::new(x).map_err(ParsePosNonzeroError::Creation) } }