diff options
author | Stephan Sokolow <http://www.ssokolow.com/ContactMe> | 2019-10-24 20:44:39 -0400 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-10-25 22:33:03 +0200 |
commit | 9273f3f45f7418e87b6e53baef78612ef0d6c5e7 (patch) | |
tree | b28dad7e08dcd45cfa53337cd5bd5b50fa6a6472 /src | |
parent | 9a2e1124bc97a003ad8916a17653ff2d1fa4250d (diff) | |
download | dialog-rs-9273f3f45f7418e87b6e53baef78612ef0d6c5e7.tar.gz dialog-rs-9273f3f45f7418e87b6e53baef78612ef0d6c5e7.tar.bz2 |
Fix clippy complaints that don't change the semantics
(Clippy also complains about `new()` without `impl Default`)
Diffstat (limited to 'src')
-rw-r--r-- | src/backends/dialog.rs | 22 | ||||
-rw-r--r-- | src/backends/kdialog.rs | 32 | ||||
-rw-r--r-- | src/backends/mod.rs | 2 | ||||
-rw-r--r-- | src/backends/stdio.rs | 2 | ||||
-rw-r--r-- | src/backends/zenity.rs | 34 |
5 files changed, 41 insertions, 51 deletions
diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs index e681caf..85b0294 100644 --- a/src/backends/dialog.rs +++ b/src/backends/dialog.rs @@ -111,19 +111,17 @@ fn get_choice(status: process::ExitStatus) -> Result<Choice> { fn get_stderr(output: process::Output) -> Result<Option<String>> { if output.status.success() { String::from_utf8(output.stderr) - .map(|s| Some(s)) - .map_err(|err| Error::from(err)) - } else { - if let Some(code) = output.status.code() { - match code { - 0 => Ok(None), - 1 => Ok(None), - 255 => Ok(None), - _ => Err(Error::from(("dialog", output.status))), - } - } else { - Err(Error::from(("dialog", output.status))) + .map(Some) + .map_err(Error::from) + } else if let Some(code) = output.status.code() { + match code { + 0 => Ok(None), + 1 => Ok(None), + 255 => Ok(None), + _ => Err(Error::from(("dialog", output.status))), } + } else { + Err(Error::from(("dialog", output.status))) } } diff --git a/src/backends/kdialog.rs b/src/backends/kdialog.rs index 153e4c5..34070c4 100644 --- a/src/backends/kdialog.rs +++ b/src/backends/kdialog.rs @@ -72,15 +72,13 @@ impl AsRef<KDialog> for KDialog { fn require_success(status: process::ExitStatus) -> Result<()> { if status.success() { Ok(()) - } else { - if let Some(code) = status.code() { - match code { - CANCEL => Ok(()), - _ => Err(Error::from(("kdialog", status))), - } - } else { - Err(Error::from(("kdialog", status))) + } else if let Some(code) = status.code() { + match code { + CANCEL => Ok(()), + _ => Err(Error::from(("kdialog", status))), } + } else { + Err(Error::from(("kdialog", status))) } } @@ -100,17 +98,15 @@ fn get_stdout(output: process::Output) -> Result<Option<String>> { if output.status.success() { String::from_utf8(output.stdout) .map(|s| Some(s.trim_end_matches('\n').to_string())) - .map_err(|err| Error::from(err)) - } else { - if let Some(code) = output.status.code() { - match code { - OK => Ok(None), - CANCEL => Ok(None), - _ => Err(Error::from(("kdialog", output.status))), - } - } else { - Err(Error::from(("kdialog", output.status))) + .map_err(Error::from) + } else if let Some(code) = output.status.code() { + match code { + OK => Ok(None), + CANCEL => Ok(None), + _ => Err(Error::from(("kdialog", output.status))), } + } else { + Err(Error::from(("kdialog", output.status))) } } diff --git a/src/backends/mod.rs b/src/backends/mod.rs index f69322f..1331323 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -41,7 +41,7 @@ pub trait Backend { pub(crate) fn is_available(name: &str) -> bool { if let Ok(path) = env::var("PATH") { - for part in path.split(":") { + for part in path.split(':') { if path::Path::new(part).join(name).exists() { return true; } diff --git a/src/backends/stdio.rs b/src/backends/stdio.rs index 6838ef1..4e4c8ec 100644 --- a/src/backends/stdio.rs +++ b/src/backends/stdio.rs @@ -35,7 +35,7 @@ fn print_title(title: &Option<String>) { fn read_input() -> Result<String> { let mut input = String::new(); io::stdin().read_line(&mut input)?; - Ok(input.trim_end_matches("\n").to_string()) + Ok(input.trim_end_matches('\n').to_string()) } fn parse_choice(input: &str) -> Choice { diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index 85206b3..12e052b 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -101,15 +101,13 @@ impl AsRef<Zenity> for Zenity { fn require_success(status: process::ExitStatus) -> Result<()> { if status.success() { Ok(()) - } else { - if let Some(code) = status.code() { - match code { - 5 => Ok(()), - _ => Err(Error::from(("zenity", status))), - } - } else { - Err(Error::from(("zenity", status))) + } else if let Some(code) = status.code() { + match code { + 5 => Ok(()), + _ => Err(Error::from(("zenity", status))), } + } else { + Err(Error::from(("zenity", status))) } } @@ -130,18 +128,16 @@ fn get_stdout(output: process::Output) -> Result<Option<String>> { if output.status.success() { String::from_utf8(output.stdout) .map(|s| Some(s.trim_end_matches('\n').to_string())) - .map_err(|err| Error::from(err)) - } else { - if let Some(code) = output.status.code() { - match code { - 0 => Ok(None), - 1 => Ok(None), - 5 => Ok(None), - _ => Err(Error::from(("zenity", output.status))), - } - } else { - Err(Error::from(("zenity", output.status))) + .map_err(Error::from) + } else if let Some(code) = output.status.code() { + match code { + 0 => Ok(None), + 1 => Ok(None), + 5 => Ok(None), + _ => Err(Error::from(("zenity", output.status))), } + } else { + Err(Error::from(("zenity", output.status))) } } |