-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rustlings error6.rs #146
Comments
我在这个页面做了解答并测试通过:https://codechina.csdn.net/u011732390/morningglory/-/tree/master/step0/errors/error6 |
impl ParsePosNonzeroError { fn parse_pos_nonzero(s: &str) } |
There are two ways to handle.
for the second way: fn parse_pos_nonzero(s: &str) -> Result<PositiveNonzeroInteger, ParsePosNonzeroError> {
let x: i64 = s.parse().map_err(ParsePosNonzeroError::from_parseInt)?;
PositiveNonzeroInteger::new(x).map_err(ParsePosNonzeroError::from_creation)
} |
with nested match exp: match s.parse() {
Ok(x) => PositiveNonzeroInteger::new(x).map_err(ParsePosNonzeroError::Creation),
Err(err) => Err(ParsePosNonzeroError::ParseInt(err)),
} |
寻求一下rustlings error_handling 部分的error6.rs的解答思路
(Rustings好像这一部分有变化,有的版本可能没有error6)
题目链接:
https://github.com/rust-lang/rustlings/blob/main/exercises/error_handling/errors6.rs
The text was updated successfully, but these errors were encountered: