summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-06-28 04:00:48 -0500
committertom barrett <spalf0@gmail.com>2018-06-28 04:00:48 -0500
commit828f0d83dcb258a8e5efd55a7775592c6e5f77bc (patch)
treed99dfba7357a5e2cbf8162fe037f2f0fd5a87482
parentae79327d4f0ee6de0ef6b8e3c51299aebfe3bc25 (diff)
-moved over it if let from bad matches
-rw-r--r--src/client/dashboard.rs11
-rw-r--r--src/client/engines.rs19
-rw-r--r--src/client/mining.rs19
-rw-r--r--src/client/navigation.rs29
-rw-r--r--src/client/refinery.rs19
-rw-r--r--src/modules/construction.rs13
-rw-r--r--src/modules/mining.rs11
-rw-r--r--src/modules/navigation.rs29
-rw-r--r--src/modules/refinery.rs11
-rw-r--r--src/server/construction.rs11
-rw-r--r--src/server/engines.rs19
-rw-r--r--src/server/mining.rs31
-rw-r--r--src/server/navigation.rs18
-rw-r--r--src/server/refinery.rs10
14 files changed, 100 insertions, 150 deletions
diff --git a/src/client/dashboard.rs b/src/client/dashboard.rs
index cbc55ba..5815ee2 100644
--- a/src/client/dashboard.rs
+++ b/src/client/dashboard.rs
@@ -23,14 +23,11 @@ pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
termion::cursor::Goto(1,1),
ship).unwrap();
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap() as char;
- if c == 'q' {
- break;
- }
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap() as char;
+ if c == 'q' {
+ break;
}
- None => (),
}
stdout.flush().unwrap();
}
diff --git a/src/client/engines.rs b/src/client/engines.rs
index 6c6b384..9b2d314 100644
--- a/src/client/engines.rs
+++ b/src/client/engines.rs
@@ -30,18 +30,15 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
write!(stdout, "{}t : accelerate torwards target", termion::cursor::Goto(1, 7)).unwrap();
}
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap();
+ let mut send = String::new();
+ send.push(c as char);
+ if send.as_bytes() == b"q" {
+ break;
}
- None => ()
+ send.push_str("\n");
+ stream.write(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/mining.rs b/src/client/mining.rs
index 80cd611..221f7ce 100644
--- a/src/client/mining.rs
+++ b/src/client/mining.rs
@@ -38,18 +38,15 @@ pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
false => write!(stdout, "{}Ship has no astroid targeted.", clear).unwrap(),
}
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap();
+ let mut send = String::new();
+ send.push(c as char);
+ if send.as_bytes() == b"q" {
+ break;
}
- None => ()
+ send.push_str("\n");
+ stream.write(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/navigation.rs b/src/client/navigation.rs
index 9bc13f9..34e1b7a 100644
--- a/src/client/navigation.rs
+++ b/src/client/navigation.rs
@@ -44,23 +44,20 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf
).unwrap();
}
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap() as char;
- if c == 'q' {
- break;
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap() as char;
+ if c == 'q' {
+ break;
+ }
+ else {
+ let i = c.to_digit(10).unwrap() as usize;
+ if i < within_range.len() {
+ let mut send = String::new();
+ send.push_str(within_range.iter().nth(i).unwrap().0);
+ send.push_str("\n");
+ stream.write(send.as_bytes()).unwrap();
}
- else {
- let i = c.to_digit(10).unwrap() as usize;
- if i < within_range.len() {
- let mut send = String::new();
- send.push_str(within_range.iter().nth(i).unwrap().0);
- send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
- }
- }
- },
- None => (),
+ }
}
}
stdout.flush().unwrap();
diff --git a/src/client/refinery.rs b/src/client/refinery.rs
index 5f126bf..013172d 100644
--- a/src/client/refinery.rs
+++ b/src/client/refinery.rs
@@ -32,18 +32,15 @@ pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>
false => write!(stdout, "{}You have no refinable minerals.", clear).unwrap(),
}
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap();
+ let mut send = String::new();
+ send.push(c as char);
+ if send.as_bytes() == b"q" {
+ break;
}
- None => ()
+ send.push_str("\n");
+ stream.write(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/modules/construction.rs b/src/modules/construction.rs
index 22086a5..46ddbb1 100644
--- a/src/modules/construction.rs
+++ b/src/modules/construction.rs
@@ -27,14 +27,11 @@ impl Construction {
}
pub fn process(&mut self) {
- match self.start.clone() {
- Some(timer) => {
- if timer.elapsed().unwrap().as_secs() > self.time {
- self.start = Some(SystemTime::now());
- self.status = ConstructionStatus::Constructed;
- }
+ if let Some(timer) = self.start.clone() {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.start = Some(SystemTime::now());
+ self.status = ConstructionStatus::Constructed;
}
- _ => (),
}
}
@@ -56,6 +53,6 @@ impl Construction {
}
pub fn take(&mut self) {
- self.status = ConstructionStatus::None;
+ self.off()
}
}
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
index 7a6461a..3c091b9 100644
--- a/src/modules/mining.rs
+++ b/src/modules/mining.rs
@@ -26,14 +26,11 @@ impl Mining {
}
pub fn process(&mut self) {
- match self.start.clone() {
- Some(timer) => {
- if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = MiningStatus::Mined;
- self.start = Some(SystemTime::now());
- }
+ if let Some(timer) = self.start.clone() {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.status = MiningStatus::Mined;
+ self.start = Some(SystemTime::now());
}
- _ => (),
}
}
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
index c4b3224..84f315c 100644
--- a/src/modules/navigation.rs
+++ b/src/modules/navigation.rs
@@ -32,19 +32,11 @@ impl Navigation {
}
pub fn process(&mut self) {
- match self.start.clone() {
- Some(timer) => {
- if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = NavigationStatus::Targeted;
- self.start = None;
- }
+ if let Some(timer) = self.start.clone() {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.status = NavigationStatus::Targeted;
+ self.start = None;
}
- _ => (),
- }
-
- match self.target_name {
- None => self.status = NavigationStatus::None,
- _ => (),
}
}
@@ -55,15 +47,12 @@ impl Navigation {
}
pub fn verify_target(&mut self, ship_position : (f64, f64, f64), masses : &HashMap<String, Mass>) {
- match self.target_name.clone() {
- Some(name) => {
- let target = masses.get(&name).unwrap();
- if distance(target.position, ship_position) > self.range {
- self.target_name = None;
- self.status = NavigationStatus::None;
- }
+ if let Some(name) = self.target_name.clone() {
+ let target = masses.get(&name).unwrap();
+ if distance(target.position, ship_position) > self.range {
+ self.target_name = None;
+ self.status = NavigationStatus::None;
}
- _ => (),
}
}
}
diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs
index cdb5de0..5100f3d 100644
--- a/src/modules/refinery.rs
+++ b/src/modules/refinery.rs
@@ -24,14 +24,11 @@ impl Refinery {
}
pub fn process(&mut self) {
- match self.start.clone() {
- Some(timer) => {
- if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = RefineryStatus::Refined;
- self.start = Some(SystemTime::now());
- }
+ if let Some(timer) = self.start.clone() {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.status = RefineryStatus::Refined;
+ self.start = Some(SystemTime::now());
}
- _ => (),
}
}
diff --git a/src/server/construction.rs b/src/server/construction.rs
index 0eb2179..94a6b0f 100644
--- a/src/server/construction.rs
+++ b/src/server/construction.rs
@@ -32,6 +32,7 @@ impl ServerConnection {
}
if construction_data.status == ConstructionStatus::Constructed {
+ println!("inserted");
construction.take();
masses.insert("Station".to_string(), Mass::new_station(ModuleType::Refinery, ship_clone.position, ship_clone.velocity));
}
@@ -42,14 +43,13 @@ impl ServerConnection {
fn txrx_construction(&mut self, construction_data : &ConstructionData) -> bool {
let send = serde_json::to_string(construction_data).unwrap() + "\n";
- match self.stream.write(send.as_bytes()) {
- Err(_error) => self.open = false,
- _ => (),
+ if let Err(_err) = self.stream.write(send.as_bytes()) {
+ self.open = false;
}
let mut recv = String::new();
- match self.buff_r.read_line(&mut recv) {
- Ok(result) => match recv.as_bytes() {
+ if let Ok(result) = self.buff_r.read_line(&mut recv) {
+ match recv.as_bytes() {
b"c\n" => {
if construction_data.has_refined {
return true
@@ -61,7 +61,6 @@ impl ServerConnection {
}
},
}
- _ => (),
}
false
diff --git a/src/server/engines.rs b/src/server/engines.rs
index 2c96920..c0d4ad5 100644
--- a/src/server/engines.rs
+++ b/src/server/engines.rs
@@ -20,24 +20,21 @@ impl ServerConnection {
let targeted = navigation.status == NavigationStatus::Targeted;
let send = serde_json::to_string(&targeted).unwrap() + "\n";
- match self.stream.write(send.as_bytes()) {
- Ok(_result) => (),
- Err(_error) => self.open = false,
+ if let Err(_err) = self.stream.write(send.as_bytes()) {
+ self.open = false;
}
let target = match navigation.target_name {
Some(name) => masses.get(&name),
None => None,
};
+
let mut recv = String::new();
- match self.buff_r.read_line(&mut recv) {
- Ok(result) => {
- engines.give_client_data(&ship_clone, target, recv);
- if result == 0 {
- self.open = false;
- }
- },
- Err(_error) => (),
+ if let Ok(result) = self.buff_r.read_line(&mut recv) {
+ engines.give_client_data(&ship_clone, target, recv);
+ if result == 0 {
+ self.open = false;
+ }
}
}
diff --git a/src/server/mining.rs b/src/server/mining.rs
index 115c034..bfe9223 100644
--- a/src/server/mining.rs
+++ b/src/server/mining.rs
@@ -42,26 +42,19 @@ impl ServerConnection {
else {
if mining.status == MiningStatus::Mined {
mining.take();
- match navigation.target_name.clone() {
- Some(name) => {
- let target = masses.get_mut(&name).unwrap();
- item = target.take("Mineral");
- }
- _ => (),
+ if let Some(name) = navigation.target_name.clone() {
+ let target = masses.get_mut(&name).unwrap();
+ item = target.take("Mineral");
}
}
}
}
- match item {
- Some(item) => match ship.give(item.clone()) {
- false => {
- let mass = Mass::new_item(item.clone(), ship.position, ship.velocity);
- masses.insert(item.name.clone(), mass);
- }
- true => (),
+ if let Some(item) = item {
+ if !ship.give(item.clone()) {
+ let mass = Mass::new_item(item.clone(), ship.position, ship.velocity);
+ masses.insert(item.name.clone(), mass);
}
- None => (),
}
masses.insert(self.name.clone(), ship);
@@ -69,14 +62,13 @@ impl ServerConnection {
fn txrx_mining(&mut self, mining_data : &MiningData) -> bool {
let send = serde_json::to_string(mining_data).unwrap() + "\n";
- match self.stream.write(send.as_bytes()) {
- Err(_error) => self.open = false,
- _ => (),
+ if let Err(_err) = self.stream.write(send.as_bytes()) {
+ self.open = false;
}
let mut recv = String::new();
- match self.buff_r.read_line(&mut recv) {
- Ok(result) => match recv.as_bytes() {
+ if let Ok(result) = self.buff_r.read_line(&mut recv) {
+ match recv.as_bytes() {
b"F\n" => {
if mining_data.is_within_range {
return true;
@@ -88,7 +80,6 @@ impl ServerConnection {
}
},
}
- _ => (),
}
false
}
diff --git a/src/server/navigation.rs b/src/server/navigation.rs
index 461a2b8..3eaaa8d 100644
--- a/src/server/navigation.rs
+++ b/src/server/navigation.rs
@@ -24,18 +24,18 @@ impl ServerConnection {
if self.open {
let send = serde_json::to_string(&within_range).unwrap() + "\n";
- match self.stream.write(send.as_bytes()) {
- Ok(_result) => (),
- Err(_error) => self.open = false,
+ if let Err(_err) = self.stream.write(send.as_bytes()) {
+ self.open = false;
};
let mut recv = String::new();
- match self.buff_r.read_line(&mut recv) {
- Ok(_result) => (),
- Err(_error) => (),
- }
- if !recv.is_empty() {
- navigation.give_target(recv.replace("\n", ""));
+ if let Ok(result) = self.buff_r.read_line(&mut recv) {
+ if result == 0 {
+ self.open = false;
+ }
+ if !recv.is_empty() {
+ navigation.give_target(recv.replace("\n", ""));
+ }
}
}
}
diff --git a/src/server/refinery.rs b/src/server/refinery.rs
index 1f7628f..eb82bb2 100644
--- a/src/server/refinery.rs
+++ b/src/server/refinery.rs
@@ -55,14 +55,13 @@ impl ServerConnection {
fn txrx_refinery(&mut self, refinery_data : &RefineryData) -> bool {
let send = serde_json::to_string(refinery_data).unwrap() + "\n";
- match self.stream.write(send.as_bytes()) {
- Err(_error) => self.open = false,
- _ => (),
+ if let Err(_err) = self.stream.write(send.as_bytes()) {
+ self.open = false;
}
let mut recv = String::new();
- match self.buff_r.read_line(&mut recv) {
- Ok(result) => match recv.as_bytes() {
+ if let Ok(result) = self.buff_r.read_line(&mut recv) {
+ match recv.as_bytes() {
b"R\n" => {
if refinery_data.has_minerals {
return true
@@ -74,7 +73,6 @@ impl ServerConnection {
}
},
}
- _ => (),
}
false