From 828f0d83dcb258a8e5efd55a7775592c6e5f77bc Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 28 Jun 2018 04:00:48 -0500 Subject: -moved over it if let from bad matches --- src/client/dashboard.rs | 11 ++++------- src/client/engines.rs | 19 ++++++++----------- src/client/mining.rs | 19 ++++++++----------- src/client/navigation.rs | 29 +++++++++++++---------------- src/client/refinery.rs | 19 ++++++++----------- 5 files changed, 41 insertions(+), 56 deletions(-) (limited to 'src/client') 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) { 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) 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) 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 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(); -- cgit v1.2.3