Use if-else statements instead of boolean match

This was a hint by `cargo clippy`
This commit is contained in:
Chris Aumann 2017-04-10 00:17:03 +02:00
parent 780b54b34e
commit df72aaf977
2 changed files with 13 additions and 9 deletions

View File

@ -116,9 +116,11 @@ pub fn get_args() -> Args {
let paths = values_t!(args.values_of("path"), String).unwrap_or(vec![String::from(".")]); let paths = values_t!(args.values_of("path"), String).unwrap_or(vec![String::from(".")]);
// Treat --kill as --signal SIGKILL (for compatibility with older syntax) // Treat --kill as --signal SIGKILL (for compatibility with older syntax)
let signal = match args.is_present("kill") { let signal = if args.is_present("kill") {
true => Some("SIGKILL".to_string()), Some("SIGKILL".to_string())
false => args.value_of("signal").map(str::to_string), // Convert Option<&str> to Option<String> } else {
// Convert Option<&str> to Option<String>
args.value_of("signal").map(str::to_string)
}; };
let mut filters = values_t!(args.values_of("filter"), String).unwrap_or(vec![]); let mut filters = values_t!(args.values_of("filter"), String).unwrap_or(vec![]);

View File

@ -35,17 +35,19 @@ mod imp {
// but is a little less performant and can cause trouble when using custom signals // but is a little less performant and can cause trouble when using custom signals
// (e.g. --signal SIGHUP) // (e.g. --signal SIGHUP)
let mut iter_args = cmd.split_whitespace(); let mut iter_args = cmd.split_whitespace();
let arg0 = match no_shell { let arg0 = if no_shell {
true => iter_args.next().unwrap(), iter_args.next().unwrap()
false => "sh", } else {
"sh"
}; };
// TODO: There might be a better way of doing this with &str. // TODO: There might be a better way of doing this with &str.
// I've had to fall back to String, as I wasn't able to join(" ") a Vec<&str> // I've had to fall back to String, as I wasn't able to join(" ") a Vec<&str>
// into a &str // into a &str
let args: Vec<String> = match no_shell { let args: Vec<String> = if no_shell {
true => iter_args.map(str::to_string).collect(), iter_args.map(str::to_string).collect()
false => vec!["-c".to_string(), iter_args.collect::<Vec<&str>>().join(" ")], } else {
vec!["-c".to_string(), iter_args.collect::<Vec<&str>>().join(" ")]
}; };
let mut command = Command::new(arg0); let mut command = Command::new(arg0);