// Hey there coder! Here's your boilerplate find enemy function! Use it wisely!
Hey there coder. Here's your boilerplate find enemy function. Use it wisely!
Hey there coder . Here ' s your boilerplate find enemy function . Use it wisely!
fn find_enemy(scan: Vec<&RadarPing>) -> Option<RadarPing> {
     if let Some(enemy) = scan.iter().filter(|e| e.foe).collect::<Vec<_>>().get(0) {
          let ping = RadarPing {
               id: enemy.id.to_string(),
               location: Point::new(enemy.location.x, enemy.location.y),
               foe: enemy.foe,
               distance: enemy.distance
          };
          Some(ping)
     } else {
          None
     }
}
fn find_enemy ( scan : Vec < & RadarPing > ) -> Option < RadarPing > { if let Some ( enemy ) = scan . iter ( ) . filter ( | e | e . foe ) . collect :: < Vec < _ > > ( ) . get ( 0 ) { let ping = RadarPing { id : enemy . id . to_string ( ) , location : Point :: new ( enemy . location . x , enemy . location . y ) , foe : enemy . foe , distance : enemy . distance } ; Some ( ping ) } else { None } }
Hey there coder!
Hey there coder!
scan
Vec<&RadarPing>