mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
day6
This commit is contained in:
parent
92d6fac7aa
commit
35f19d8e5e
@ -25,13 +25,21 @@ impl ParsePosNonzeroError {
|
||||
}
|
||||
// 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<PositiveNonzeroInteger, ParsePosNonzeroError> {
|
||||
// TODO: change this to return an appropriate error instead of panicking
|
||||
// when `parse()` returns an error.
|
||||
let x: i64 = s.parse().unwrap();
|
||||
PositiveNonzeroInteger::new(x).map_err(ParsePosNonzeroError::from_creation)
|
||||
// let x: i64 = s.parse().unwrap();
|
||||
let res = s.parse();
|
||||
match res {
|
||||
Ok(x) => PositiveNonzeroInteger::new(x).map_err(ParsePosNonzeroError::from_creation),
|
||||
Err(err) => Err(ParsePosNonzeroError::from_parseint(err)),
|
||||
}
|
||||
// PositiveNonzeroInteger::new(x).map_err(ParsePosNonzeroError::from_creation)
|
||||
}
|
||||
|
||||
// Don't change anything below this line.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user