I have this code:
fn make_guess() -> u32 {
loop {
let mut guess = String::new();
io::stdin().read_line(&mut guess)
.ok()
.expect("Failed to read line");
match guess.trim().parse() {
Ok(num) => return num,
Err(_) => {
println!("Please input a number!");
continue;
}
};
break;
}
}
When I run this code, the compiler complains:
expected `u32`,
found `()`
Apparently, it break;
returns a void value. However, it is impossible to achieve break;
because of return
and continue
.
Actually, if I delete break;
, this works fine.
Is this a bug in the compiler or for some reason?
source
share