A while back there was talk about trying to make pattern matching (particularly when ref, match, and * are involved) more ergonomic and stumbled across a particularly annoying edge case which reminded me of it.
Is there any more news on this?
My particular example is that I’m iterating over a Vec<(usize, Bot)> and want to update each Bot. Currently I’ve got to write a big mess of &mut and ref to make the compiler happy:
for &mut (tok, ref mut bot) in &mut self.bots {
let actions = bot.tick(&self.game_state);
debug!("Bot {} executed {:?}", tok, actions);
}
Whereas it’d be much easier (and arguably just as understandable) if pattern matching could elide away the boilerplate so I can write something like this:
for (tok, mut bot) in &mut self.bots {
let actions = bot.tick(&self.game_state);
debug!("Bot {} executed {:?}", tok, actions);
}
In theory the compiler should be able to automatically dereference the tuple reference, then that because mut bot is trying to use a mutably borrowed thing it’ll automatically insert ref mut bot.