更新时间:2023-11-10 15:50:28
这是一个包含所有可选类型注释和错误处理的版本,可能对像我这样的初学者很有用:
Here is a version with all optional type annotations and error handling which may be useful for beginners like me:
use std::io;
fn main() {
let mut input_text = String::new();
io::stdin()
.read_line(&mut input_text)
.expect("failed to read from stdin");
let trimmed = input_text.trim();
match trimmed.parse::<u32>() {
Ok(i) => println!("your integer input: {}", i),
Err(..) => println!("this was not an integer: {}", trimmed),
};
}