diff options
Diffstat (limited to 'src/bin/server.rs')
-rw-r--r-- | src/bin/server.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/bin/server.rs b/src/bin/server.rs index e20acf6..ea961b7 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -1,16 +1,16 @@ extern crate space; +use std::collections::HashMap; +use std::net::TcpListener; use std::thread::sleep; use std::time::Duration; -use std::net::TcpListener; -use std::collections::HashMap; use space::mass::Mass; use space::math::rand_name; use space::server::connection::ServerConnection; fn populate() -> HashMap<String, Mass> { - let mut masses : HashMap<String, Mass> = HashMap::new(); + let mut masses: HashMap<String, Mass> = HashMap::new(); for _ in 0..10 { masses.insert(rand_name(), Mass::new_astroid()); @@ -25,23 +25,23 @@ fn main() { let mut masses = populate(); - let mut connections : Vec<ServerConnection> = Vec::new(); + let mut connections: Vec<ServerConnection> = Vec::new(); for stream in listener.incoming() { match stream { Ok(stream) => { let new_connection = ServerConnection::new(stream, &mut masses); - let exists = connections.iter().position(|connection| - connection.name == new_connection.name && - connection.module_type == new_connection.module_type); - match exists { - Some(index) => { connections.remove(index); }, - _ => (), + let exists = connections.iter().position(|connection| { + connection.name == new_connection.name + && connection.module_type == new_connection.module_type + }); + if let Some(index) = exists { + connections.remove(index); } connections.push(new_connection); - }, + } _ => { - for i in 0..connections.len() { - connections[i].process(&mut masses); + for connection in &mut connections { + connection.process(&mut masses); } for mass in masses.values_mut() { @@ -49,7 +49,7 @@ fn main() { } sleep(Duration::from_millis(100)); - }, + } } } } |