Skip to content

Instantly share code, notes, and snippets.

@kiwiyou
Created January 11, 2020 06:54
Show Gist options
  • Save kiwiyou/ee07991291fa9120d2e3858948c64b45 to your computer and use it in GitHub Desktop.
Save kiwiyou/ee07991291fa9120d2e3858948c64b45 to your computer and use it in GitHub Desktop.
Read lines from stdin until one can be parsed
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