From 42a491f8b1b7c7bb56a1e744850cc7f2ca8f0de2 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Thu, 7 Mar 2019 19:25:50 +0100 Subject: Clean up as suggested by clippy --- src/tftpc.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src/tftpc.rs') diff --git a/src/tftpc.rs b/src/tftpc.rs index 6aa61c9..669b455 100644 --- a/src/tftpc.rs +++ b/src/tftpc.rs @@ -36,7 +36,7 @@ impl Tftpc { pub fn new(conf: Configuration) -> Tftpc { Tftpc { tftp: rtftp::Tftp::new(), - conf: conf, + conf, } } @@ -148,11 +148,11 @@ impl Tftpc { } match self.tftp.send_file(&sock, &mut file) { - Ok(_) => return Ok(format!("Sent {} to {}.", self.conf.filename.display(), self.conf.remote)), + Ok(_) => Ok(format!("Sent {} to {}.", self.conf.filename.display(), self.conf.remote)), Err(err) => { let error = format!("Sending {} to {} failed ({}).", self.conf.filename.display(), self.conf.remote, err); self.tftp.send_error(&sock, 0, "Sending error")?; - return Err(io::Error::new(err.kind(), error)); + Err(io::Error::new(err.kind(), error)) }, } } @@ -197,11 +197,11 @@ impl Tftpc { } match self.tftp.recv_file(&sock, &mut file) { - Ok(_) => return Ok(format!("Received {} from {}.", self.conf.filename.display(), self.conf.remote)), + Ok(_) => Ok(format!("Received {} from {}.", self.conf.filename.display(), self.conf.remote)), Err(err) => { let error = format!("Receiving {} from {} failed ({}).", self.conf.filename.display(), self.conf.remote, err); self.tftp.send_error(&sock, 0, "Receiving error")?; - return Err(std::io::Error::new(err.kind(), error)); + Err(std::io::Error::new(err.kind(), error)) }, } } @@ -232,7 +232,7 @@ fn usage(opts: Options, program: String, error: Option) { println!("{}", opts.usage(format!("RusTFTP\n\n{} [options] [:port]", program).as_str())); } -fn parse_commandline<'a>(args: &'a Vec) -> Result { +fn parse_commandline(args: &[String]) -> Result { let program = args[0].clone(); let mut mode = None; let mut filename = None; @@ -255,19 +255,13 @@ fn parse_commandline<'a>(args: &'a Vec) -> Result { - mode = Some(Mode::RRQ); - filename = Some(Path::new(&f).to_path_buf()); - } - None => () + if let Some(f) = matches.opt_str("g") { + mode = Some(Mode::RRQ); + filename = Some(Path::new(&f).to_path_buf()); } - match matches.opt_str("p") { - Some(f) => { - mode = Some(Mode::WRQ); - filename = Some(Path::new(&f).to_path_buf()); - } - None => () + if let Some(f) = matches.opt_str("p") { + mode = Some(Mode::WRQ); + filename = Some(Path::new(&f).to_path_buf()); } if mode.is_none() || (matches.opt_present("g") && matches.opt_present("p")) { @@ -301,7 +295,7 @@ fn parse_commandline<'a>(args: &'a Vec) -> Result