Question about "Speaker Notes" in Destructuring page
sahuang opened this issue · 2 comments
sahuang commented
The "Speaker Notes" in Destructuring Enums mentioned that:
Save the result of
divide_in_two
in theresult
variable andmatch
it in a loop. That won’t compile becausemsg
is consumed when matched. To fix it, match&result
instead ofresult
. That will makemsg
a reference so it won’t be consumed.
However, I tried this and it compiles successfully even without the &
. Is it because new rustc
version somehow fixed this issue?
djmitche commented
I think the missing bit is "in a loop"
fn main() {
let n = 100;
let result = divide_in_two(n);
loop {
match result {
Result::Ok(half) => println!("{n} divided in two is {half}"),
Result::Err(msg) => println!("sorry, an error happened: {msg}"),
}
}
}
BTW, please try to use text to represent text, rather than images -- in this case I couldn't copy/paste from your example because it's an image.
sahuang commented
Thanks! Noted.