diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs index 8097b490..953c3aec 100644 --- a/exercises/error_handling/errors6.rs +++ b/exercises/error_handling/errors6.rs @@ -8,7 +8,7 @@ // Execute `rustlings hint errors6` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE + use std::num::ParseIntError; @@ -24,13 +24,15 @@ impl ParsePosNonzeroError { ParsePosNonzeroError::Creation(err) } // TODO: add another error conversion function here. - // fn from_parseint... + fn from_parseint(err: ParseIntError)-> ParsePosNonzeroError{ + ParsePosNonzeroError::ParseInt(err) + } } fn parse_pos_nonzero(s: &str) -> Result { // TODO: change this to return an appropriate error instead of panicking // when `parse()` returns an error. - let x: i64 = s.parse().unwrap(); + let x: i64 = s.parse().map_err(ParsePosNonzeroError::from_parseint)?; PositiveNonzeroInteger::new(x).map_err(ParsePosNonzeroError::from_creation) }