Created
January 11, 2020 06:54
-
-
Save kiwiyou/ee07991291fa9120d2e3858948c64b45 to your computer and use it in GitHub Desktop.
Read lines from stdin until one can be parsed
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
use std::io::{stdin, BufRead}; | |
fn main() { | |
let input: u32 = stdin() | |
.lock() | |
.lines() | |
.find_map(|line| line.expect("Failed to read.").trim().parse().ok()) | |
.unwrap(); | |
println!("{}", input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment