enum Foo {
Alpha(i32),
Beta
}
struct Container {
value: Foo,
}
fn main() {
let mut cont = Some(Container { value: Foo::Alpha(10) });
let mut a = 0;
if let Some(mut c) = &cont {
match &mut c.value {
Foo::Alpha(i) => *i += a,
Foo::Beta => a = 5,
}
}
if let Some(c) = cont {
match c.value {
Foo::Alpha(i) => println!("{i}"),
Foo::Beta => ()
}
}
}
In this example, I don't understand why cont loses ownership of the container in the first part. I make a mutable reference to it, then I don't read cont again until the reference is out of scope, at which point it is supposed to return to cont.