Created
April 20, 2019 03:36
-
-
Save rust-play/2b2755048f18cc731ae952381ac87a65 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(try_blocks)] | |
fn main() { | |
use std::num::ParseIntError; | |
let result: Result<i32, ParseIntError> = try { | |
"1".parse::<i32>()? | |
+ "2".parse::<i32>()? | |
+ "3".parse::<i32>()? | |
}; | |
assert_eq!(result, Ok(6)); | |
let result: Result<i32, ParseIntError> = try { | |
"1".parse::<i32>()? | |
+ "foo".parse::<i32>()? | |
+ "3".parse::<i32>()? | |
}; | |
assert!(result.is_err()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment