I would like to only clone if necessary in this line: c.src = if m.auto_resend { m.src.clone() } else { m.src };
But sadly using this logic, the compiler complains that I'm reusing a moved value below inside an if m.auto_resend block, so I have to clone all the time to make it compile. I guess the thinking is that m.auto_resend could have changed in between, but it's not even mutable and there's no async in between so I'm really annoyed by this...
Does anybody have any suggestions how to prevent unnecessary cloning here?
What you can do is put the m.src into an Option, which will be Some if and only if m.auto_resend is true. Then, pattern match that instead of testing m.auto_resend.
I guess the thinking is that m.auto_resend could have changed in between
In general, the compiler will never accept or reject a program based on reasoning about what an if condition or any other expression will evaluate at run time (except for certain "this is guaranteed to panic and you probably didn't mean that" diagnostics, if I remember correctly). Such reasoning is always necessarily incomplete, and "none of it" is a clear place to draw the line.