Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use extract_if as a replacement for drain_filter #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Game {
let revived = self
.state
.dead
.drain_filter(|corpse| corpse.respawn <= now)
.extract_if(|corpse| corpse.respawn <= now)
.map(|dead| dead.player)
.map(|player| {
println!("revived player {}", player.id);
Expand Down Expand Up @@ -236,7 +236,7 @@ impl Game {
}
}

for mut player in self.state.players.drain_filter(|player| colliding_buf.contains(&player.id)) {
for mut player in self.state.players.extract_if(|player| colliding_buf.contains(&player.id)) {
player.randomize(&mut self.rng, bounds);
self.state
.dead
Expand All @@ -249,7 +249,7 @@ impl Game {
let bounds = self.bounds();

for bullet in &mut self.state.bullets {
let deceased = self.state.players.drain_filter(|player| {
let deceased = self.state.players.extract_if(|player| {
if player.is_colliding(bullet) && bullet.player_id != player.id {
println!(
"Player {} killed player {} at ({}, {})",
Expand Down
2 changes: 1 addition & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(drain_filter)]
#![feature(extract_if)]

#[macro_use]
extern crate log;
Expand Down