aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-10-27 10:55:30 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-10-27 11:59:40 +0100
commit0970381271bd07f020a888b027653ca627e8655c (patch)
tree95f5f6f94b7851b98a78a91a851d5e3783bd5ac2
parentca06c4c4a2846b1c0410af1c7a68c65f5489a0b9 (diff)
downloaddialog-rs-0970381271bd07f020a888b027653ca627e8655c.tar.gz
dialog-rs-0970381271bd07f020a888b027653ca627e8655c.tar.bz2
Implement Default for all backend structs
This fixes the clippy warning new_without_default [0]. [0] https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/backends/dialog.rs16
-rw-r--r--src/backends/kdialog.rs4
-rw-r--r--src/backends/stdio.rs4
-rw-r--r--src/backends/zenity.rs9
5 files changed, 18 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d6256c..939ae76 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ SPDX-License-Identifier: CC0-1.0
# Unreleased
- Add the `KDialog` backend (contributed by Stephan Sokolow).
- Comply with version 3.0 of the REUSE specification.
+- Implement `Default` for all backend structs.
# v0.2.1 (2019-06-30)
- Fix the input and password dialogs for the `zenity` backend (thanks Silvano
diff --git a/src/backends/dialog.rs b/src/backends/dialog.rs
index 85b0294..8061d98 100644
--- a/src/backends/dialog.rs
+++ b/src/backends/dialog.rs
@@ -19,11 +19,7 @@ pub struct Dialog {
impl Dialog {
/// Creates a new `Dialog` instance without configuration.
pub fn new() -> Dialog {
- Dialog {
- backtitle: None,
- height: "0".to_string(),
- width: "0".to_string(),
- }
+ Default::default()
}
/// Sets the backtitle for the dialog boxes.
@@ -87,6 +83,16 @@ impl AsRef<Dialog> for Dialog {
}
}
+impl Default for Dialog {
+ fn default() -> Self {
+ Dialog {
+ backtitle: None,
+ height: "0".to_string(),
+ width: "0".to_string(),
+ }
+ }
+}
+
fn require_success(status: process::ExitStatus) -> Result<()> {
if status.success() {
Ok(())
diff --git a/src/backends/kdialog.rs b/src/backends/kdialog.rs
index 34070c4..c2ddcd0 100644
--- a/src/backends/kdialog.rs
+++ b/src/backends/kdialog.rs
@@ -20,7 +20,7 @@ const CANCEL: i32 = 1;
/// The `kdialog` backend.
///
/// This backend uses the external `kdialog` program to display KDE dialog boxes.
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct KDialog {
icon: Option<String>,
// TODO: --dontagain
@@ -29,7 +29,7 @@ pub struct KDialog {
impl KDialog {
/// Creates a new `KDialog` instance without configuration.
pub fn new() -> KDialog {
- KDialog { icon: None }
+ Default::default()
}
/// Sets the icon in the dialog box's titlebar and taskbar button.
diff --git a/src/backends/stdio.rs b/src/backends/stdio.rs
index 4e4c8ec..9a153df 100644
--- a/src/backends/stdio.rs
+++ b/src/backends/stdio.rs
@@ -9,13 +9,13 @@ use crate::{Choice, Input, Message, Password, Question, Result};
///
/// This backend is intended as a fallback backend to use if no other backend is available. The
/// dialogs are printed to the standard output and user input is read from the standard input.
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct Stdio {}
impl Stdio {
/// Creates a new `Stdio` instance.
pub fn new() -> Stdio {
- Stdio {}
+ Default::default()
}
}
diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs
index d5745eb..0deca0a 100644
--- a/src/backends/zenity.rs
+++ b/src/backends/zenity.rs
@@ -8,7 +8,7 @@ use crate::{Choice, Error, Input, Message, Password, Question, Result};
/// The `zenity` backend.
///
/// This backend uses the external `zenity` program to display GTK+ dialog boxes.
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct Zenity {
icon: Option<String>,
width: Option<String>,
@@ -19,12 +19,7 @@ pub struct Zenity {
impl Zenity {
/// Creates a new `Zenity` instance without configuration.
pub fn new() -> Zenity {
- Zenity {
- icon: None,
- width: None,
- height: None,
- timeout: None,
- }
+ Default::default()
}
/// Sets the icon of the dialog box.