我的箱子有一个小问题:这段代码有效:
fn main() {
println!("Celsius to farenheit");
print!("Insert Celsius: ");
let celsius: f32 = read!();
println!("Celsius to Farenheit is: {}", cel_to_far(celsius));
}
但是如果我使用text_io手册中的内容:
fn main() {
println!("Celsius to farenheit");
let celsius: f32 = read!("Insert Celsius: {}!");
println!("Celsius to Farenheit is: {}", cel_to_far(celsius));
}
它惊慌失措:
Celsius to farenheit
6
thread 'main' panicked at src/main.rs:4:24:
called `Result::unwrap()` on an `Err` value: UnexpectedValue(73, Some(54))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
这不是,我认为我遵循了正确的说明:
两个片段并不等同!
第一个打印
Insert Celsius:
然后读取一个整数,第二个将读取Insert Celsius:
一个整数,然后是一个!
意思,你必须输入所有这些,它不会打印它。这是第二个希望您输入所有内容的Insert Celsius: 123!