[niepce] rust: fix some clippy warnings



commit 696ce0fc5313ec6f031ec3271fc7d4e2ff3a8b61
Author: Hubert Figuière <hub figuiere net>
Date:   Sun Jan 5 11:15:57 2020 -0500

    rust: fix some clippy warnings

 crates/npc-engine/src/db/filebundle.rs    |  8 ++++----
 src/libraryclient/mod.rs                  |  5 +----
 src/niepce/ui/dialogs/confirm.rs          |  2 +-
 src/niepce/ui/dialogs/requestnewfolder.rs | 16 +++++++++-------
 src/niepce/ui/imagetoolbar.rs             | 16 ++++++----------
 5 files changed, 21 insertions(+), 26 deletions(-)
---
diff --git a/crates/npc-engine/src/db/filebundle.rs b/crates/npc-engine/src/db/filebundle.rs
index ec6c9ea..64399b8 100644
--- a/crates/npc-engine/src/db/filebundle.rs
+++ b/crates/npc-engine/src/db/filebundle.rs
@@ -125,8 +125,8 @@ impl FileBundle {
                     current_bundle.as_mut().unwrap().add(&f);
                     continue;
                 }
-                if current_bundle.is_some() {
-                    bundles.push(current_bundle.unwrap());
+                if let Some(current_bundle) = current_bundle {
+                    bundles.push(current_bundle);
                 }
                 let mut bundle = FileBundle::new();
                 bundle.add(&f);
@@ -134,8 +134,8 @@ impl FileBundle {
                 current_bundle = Some(bundle);
             }
         }
-        if current_bundle.is_some() {
-            bundles.push(current_bundle.unwrap());
+        if let Some(current_bundle) = current_bundle {
+            bundles.push(current_bundle);
         }
         bundles
     }
diff --git a/src/libraryclient/mod.rs b/src/libraryclient/mod.rs
index e2d9c02..41dd4ce 100644
--- a/src/libraryclient/mod.rs
+++ b/src/libraryclient/mod.rs
@@ -174,10 +174,7 @@ pub unsafe extern "C" fn lcchannel_new(
 ) -> *mut LcChannel {
     let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
     let source_id = receiver.attach(None, move |n: LibNotification| {
-        let mut continuation = false;
-        if cb(&n, data) != 0 {
-            continuation = true;
-        }
+        let continuation = cb(&n, data) != 0;
         glib::Continue(continuation)
     });
     Box::into_raw(Box::new(PortableChannel::<LibNotification>(
diff --git a/src/niepce/ui/dialogs/confirm.rs b/src/niepce/ui/dialogs/confirm.rs
index 0f3310a..dc32aeb 100644
--- a/src/niepce/ui/dialogs/confirm.rs
+++ b/src/niepce/ui/dialogs/confirm.rs
@@ -42,7 +42,7 @@ pub unsafe extern "C" fn dialog_confirm(
         &*msg,
     );
 
-    if dialog.run() == gtk::ResponseType::Yes.into() {
+    if dialog.run() == gtk::ResponseType::Yes {
         result = true;
     }
     dialog.destroy();
diff --git a/src/niepce/ui/dialogs/requestnewfolder.rs b/src/niepce/ui/dialogs/requestnewfolder.rs
index 3d4f4a4..6b90134 100644
--- a/src/niepce/ui/dialogs/requestnewfolder.rs
+++ b/src/niepce/ui/dialogs/requestnewfolder.rs
@@ -37,8 +37,8 @@ pub unsafe extern "C" fn dialog_request_new_folder(
         Some(&parent),
         gtk::DialogFlags::MODAL,
         &[
-            (&gettext("OK"), gtk::ResponseType::Ok.into()),
-            (&gettext("Cancel"), gtk::ResponseType::Cancel.into()),
+            (&gettext("OK"), gtk::ResponseType::Ok),
+            (&gettext("Cancel"), gtk::ResponseType::Cancel),
         ],
     );
     let label = Label::new_with_mnemonic(Some(gettext("Folder _name:").as_str()));
@@ -49,12 +49,14 @@ pub unsafe extern "C" fn dialog_request_new_folder(
     dialog.get_content_area().pack_end(&entry, true, false, 4);
 
     dialog.get_content_area().show_all();
-    let cancel = dialog.run() != gtk::ResponseType::Ok.into();
+    let cancel = dialog.run() != gtk::ResponseType::Ok;
     let folder_name = entry.get_text();
     dialog.destroy();
-    if !cancel && folder_name.is_some() {
-        client
-            .unwrap_mut()
-            .create_folder(folder_name.unwrap().to_string(), None);
+    if !cancel {
+        if let Some(folder_name) = folder_name {
+            client
+                .unwrap_mut()
+                .create_folder(folder_name.to_string(), None);
+        }
     }
 }
diff --git a/src/niepce/ui/imagetoolbar.rs b/src/niepce/ui/imagetoolbar.rs
index 21bb669..bb530b6 100644
--- a/src/niepce/ui/imagetoolbar.rs
+++ b/src/niepce/ui/imagetoolbar.rs
@@ -26,18 +26,14 @@ use gtk_sys;
 pub extern "C" fn image_toolbar_new() -> *mut gtk_sys::GtkToolbar {
     let toolbar = gtk::Toolbar::new();
 
-    let icon = gtk::Image::new_from_icon_name(
-        Some("go-previous-symbolic"),
-        gtk::IconSize::SmallToolbar.into(),
-    );
+    let icon =
+        gtk::Image::new_from_icon_name(Some("go-previous-symbolic"), gtk::IconSize::SmallToolbar);
     let tool_item = gtk::ToolButton::new(Some(&icon), None);
     tool_item.set_action_name(Some("shell.PrevImage"));
     toolbar.add(&tool_item);
 
-    let icon = gtk::Image::new_from_icon_name(
-        Some("go-next-symbolic"),
-        gtk::IconSize::SmallToolbar.into(),
-    );
+    let icon =
+        gtk::Image::new_from_icon_name(Some("go-next-symbolic"), gtk::IconSize::SmallToolbar);
     let tool_item = gtk::ToolButton::new(Some(&icon), None);
     tool_item.set_action_name(Some("shell.NextImage"));
     toolbar.add(&tool_item);
@@ -47,7 +43,7 @@ pub extern "C" fn image_toolbar_new() -> *mut gtk_sys::GtkToolbar {
 
     let icon = gtk::Image::new_from_icon_name(
         Some("object-rotate-left-symbolic"),
-        gtk::IconSize::SmallToolbar.into(),
+        gtk::IconSize::SmallToolbar,
     );
     let tool_item = gtk::ToolButton::new(Some(&icon), None);
     tool_item.set_action_name(Some("shell.RotateLeft"));
@@ -55,7 +51,7 @@ pub extern "C" fn image_toolbar_new() -> *mut gtk_sys::GtkToolbar {
 
     let icon = gtk::Image::new_from_icon_name(
         Some("object-rotate-right-symbolic"),
-        gtk::IconSize::SmallToolbar.into(),
+        gtk::IconSize::SmallToolbar,
     );
     let tool_item = gtk::ToolButton::new(Some(&icon), None);
     tool_item.set_action_name(Some("shell.RotateRight"));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]