diff --git a/materialien/read.rs b/materialien/read.rs new file mode 100755 index 0000000..df3616a --- /dev/null +++ b/materialien/read.rs @@ -0,0 +1,28 @@ +use std::str::FromStr; +use std::fmt::Display; + +fn main() { + // let x = read::(); + let x: usize = read(); + println!("{}", x); + +} + +fn read() -> T + where T: FromStr, + T::Err: Display +{ + use std::io; + + loop { + let mut s = String::new(); + io::stdin() + .read_line(&mut s) + .expect("unexpected io error"); + + match s.trim_right().parse() { + Ok(value) => return value, + Err(e) => println!("error: {}", e), + } + } +}