#Rustlang won't let you cut the branch you're sitting on.
Sometimes you need to change a complex struct or enum based on its contents. However, you can't do this inside a `match` that takes references, because the references inside the `match` keep a "lock" on the whole object and prevent it from being replaced.
The solution is to use `match` only to check the condition, and perform replacement in a separate step after the `match`.
It's better explained with code:
https://play.rust-lang.org/?gist=f7616168b8aba14a6c387a8f5df3eec7
@NfNitLoop Your code doesn't compile with `&mut Some(5)`, and difficulty of working with &Option (rather than freely movable owned Option) was the whole point of the tip.
@kornel er, helps if I include the link:
https://play.rust-lang.org/?gist=778c9d692bb996a94053c21a55d02cf6&version=stable
@NfNitLoop Eh, my original example was too simplified to show it's about unmovable content, i.e. when you have a reference to a large struct/vec or something uncloneable like a file handle.
This time you're dodging use of references by copying the contents instead.
https://play.rust-lang.org/?gist=43aa49401140a0991c563bd38ea62970
@kornel aaaah. Yeah, in that case, you can simplify things by first take()ing the value. If you can't copy it, move it instead! :)
@kornel Here's a slightly modified version that works with &mut.