Skip to content

Instantly share code, notes, and snippets.

@wingerse
Created April 24, 2018 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wingerse/9c865a4e6b3a6862746779e59aeda9b0 to your computer and use it in GitHub Desktop.
Save wingerse/9c865a4e6b3a6862746779e59aeda9b0 to your computer and use it in GitHub Desktop.
Rust reference different fields
fn tick_players(&mut self) {
for p in self.player_list.iter_mut() {
let world = self.get_world(p); // boom error taking multiple reference to self. But this is perfectly fine as it doesn't touch player_list..
p.tick(&self.server_info, world, &mut self.packet_list);
}
}
fn get_world(&mut self, dimension: Dimension) -> &mut World {
match dimension {
Dimension::Overworld => &mut self.overworld,
Dimension::Nether => &mut self.nether,
Dimension::End => &mut self.end,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment