我的板条箱有一个小问题: 此代码有效:
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
这不是,我认为我遵循了正确的说明:
两个片段并不等同!
第一个 prints
"Insert Celsius: "
然后读取一个整数,第二个将 read "Insert Celsius: "
然后是一个整数,然后是一个 "!"
意味着你必须 type 所有这些,它不会打印它。这是第二个希望您输入 Insert Celsius: 123!