From 53281aa16e262124631af4abd19e16a921de098d Mon Sep 17 00:00:00 2001 From: tom barrett Date: Fri, 23 Feb 2018 07:25:13 -0600 Subject: prettier way to filter --- src/connection.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index 1502d7a..ac57176 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -86,12 +86,9 @@ impl Connection { Module::Navigation => { let ship = &masses[self.index].downcast_ref::().unwrap(); - let mut within_range = Vec::new(); - for mass in masses.iter() { - if distance(ship.location(), mass.location()) < ship.range() { - within_range.push(mass); - } - } + let within_range : Vec<_> = masses.iter().filter(|mass| + distance(ship.location(), mass.location()) < ship.range()).collect(); + let mut send = String::new(); for mass in within_range { send.push_str(&mass.serialize()); -- cgit v1.2.3