Advertisements
I have a small problem with a crate:
This code works:
fn main() {
println!("Celsius to farenheit");
print!("Insert Celsius: ");
let celsius: f32 = read!();
println!("Celsius to Farenheit is: {}", cel_to_far(celsius));
}
But if I use what is in the manual of text_io:
fn main() {
println!("Celsius to farenheit");
let celsius: f32 = read!("Insert Celsius: {}!");
println!("Celsius to Farenheit is: {}", cel_to_far(celsius));
}
It panics:
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
This doesn’t and I think I’m following the correct instructions:
>Solution :
Both snippets are not equivalent!
The first one prints Insert Celsius:
then reads an integer, the second one will read Insert Celsius:
then an integer and then an !
meaning you have to type all that, it doesn’t print it. That is the second one expects you to type all of Insert Celsius: 123!