summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-02-23 07:25:13 -0600
committertom barrett <spalf0@gmail.com>2018-02-23 07:25:13 -0600
commit53281aa16e262124631af4abd19e16a921de098d (patch)
tree792b7a420ca7c3e859c9205a6a38cf96025a6929 /src
parentceb9ee22f32d46a6e49229f447c414f3707eb3ac (diff)
prettier way to filter
Diffstat (limited to 'src')
-rw-r--r--src/connection.rs9
1 files 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::<Ship>().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());