From f1f6b1b8099d72fced527e68a45fba39d73cd91a Mon Sep 17 00:00:00 2001 From: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:59:45 +0100 Subject: [PATCH] style: apply automated clippy lint fixes Related to #16 --- examples/client.rs | 5 +---- src/parser/mod.rs | 10 +++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index a651b6b..a8b0e37 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -60,10 +60,7 @@ fn connect(host: &str, params: &HostParams) { Some(h) => h, None => host, }; - let port = match params.port { - None => 22, - Some(p) => p, - }; + let port = params.port.unwrap_or(22); let host = match host.contains(':') { true => host.to_string(), false => format!("{}:{}", host, port), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index d866cbb..6b7ed2b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -304,7 +304,7 @@ impl SshConfigParser { /// parse boolean value fn parse_boolean(args: Vec) -> SshParserResult { - match args.get(0).map(|x| x.as_str()) { + match args.first().map(|x| x.as_str()) { Some("yes") => Ok(true), Some("no") => Ok(false), Some(_) => Err(SshParserError::ExpectedBoolean), @@ -315,7 +315,7 @@ impl SshConfigParser { /// Parse comma separated list arguments fn parse_comma_separated_list(args: Vec) -> SshParserResult> { match args - .get(0) + .first() .map(|x| x.split(',').map(|x| x.to_string()).collect()) { Some(args) => Ok(args), @@ -360,7 +360,7 @@ impl SshConfigParser { /// Parse path argument fn parse_path(args: Vec) -> SshParserResult { - if let Some(s) = args.get(0) { + if let Some(s) = args.first() { Self::parse_path_arg(s) } else { Err(SshParserError::MissingArgument) @@ -384,7 +384,7 @@ impl SshConfigParser { /// Parse port number argument fn parse_port(args: Vec) -> SshParserResult { - match args.get(0).map(|x| u16::from_str(x)) { + match args.first().map(|x| u16::from_str(x)) { Some(Ok(val)) => Ok(val), Some(Err(_)) => Err(SshParserError::ExpectedPort), None => Err(SshParserError::MissingArgument), @@ -402,7 +402,7 @@ impl SshConfigParser { /// Parse unsigned argument fn parse_unsigned(args: Vec) -> SshParserResult { - match args.get(0).map(|x| usize::from_str(x)) { + match args.first().map(|x| usize::from_str(x)) { Some(Ok(val)) => Ok(val), Some(Err(_)) => Err(SshParserError::ExpectedUnsigned), None => Err(SshParserError::MissingArgument),