From c297e871b7ce8935dd3bb1c65ecae37000d9a331 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Mon, 19 Mar 2018 05:06:50 -0500 Subject: -pass module information in a serializable way --- src/bin/client.rs | 13 +++++++++---- src/bin/server.rs | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/bin') diff --git a/src/bin/client.rs b/src/bin/client.rs index 558f914..cf12e53 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -3,11 +3,13 @@ use std::io::prelude::*; use std::io::BufReader; use std::net::TcpStream; +extern crate serde_json; + extern crate space; use space::dashboard::client_dashboard; use space::engines::client_engines; use space::navigation::client_navigation; -use space::module::{Module, from_primitive}; +use space::module::Module; fn main() { let mut name = String::new(); @@ -28,7 +30,8 @@ fn main() { let mut data = String::new(); buff_r.read_line(&mut data).unwrap(); - let modules : Vec<&str> = data.split(",").collect(); + let mut modules : Vec<&str> = data.split(";").collect(); + modules.pop(); println!("Choose your module:"); for (i, module) in modules.iter().enumerate() { @@ -37,9 +40,11 @@ fn main() { let mut choice = String::new(); io::stdin().read_line(&mut choice).expect("Failed"); - stream.write(choice.as_bytes()).unwrap(); + let mut module = modules[choice.replace("\n","").parse::().unwrap()].to_owned(); + module.push_str("\n"); + stream.write(module.as_bytes()).unwrap(); - let module = from_primitive(choice); + let module : Module = serde_json::from_str(&module.replace("\n","")).unwrap(); match module { Module::Dashboard => client_dashboard(buff_r), Module::Engines => client_engines(stream, buff_r), diff --git a/src/bin/server.rs b/src/bin/server.rs index 36840c1..16186d7 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -11,9 +11,9 @@ use space::connection::Connection; fn populate() -> Vec> { let mut masses : Vec> = Vec::new(); - masses.push(Box::new(Astroid::new())); - masses.push(Box::new(Astroid::new())); - masses.push(Box::new(Astroid::new())); + for _ in 0..10 { + masses.push(Box::new(Astroid::new())); + } masses } -- cgit v1.2.3