[niepce] rust: fix some clippy warnings



commit 59a821ab90f83407fdcf10539f88345bf53fb912
Author: Hubert Figuière <hub figuiere net>
Date:   Sat May 14 23:36:13 2022 -0400

    rust: fix some clippy warnings

 crates/npc-engine/src/db/library.rs           | 11 -----------
 crates/npc-engine/src/library/notification.rs | 14 ++++++++++++++
 niepce-main/src/libraryclient.rs              | 16 ++++++++++++++++
 niepce-main/src/niepce/ui/image_grid_view.rs  |  4 ++--
 4 files changed, 32 insertions(+), 13 deletions(-)
---
diff --git a/crates/npc-engine/src/db/library.rs b/crates/npc-engine/src/db/library.rs
index 6677062..d32a8b0 100644
--- a/crates/npc-engine/src/db/library.rs
+++ b/crates/npc-engine/src/db/library.rs
@@ -87,7 +87,6 @@ pub type Result<T> = result::Result<T, Error>;
 
 pub struct Library {
     // maindir: PathBuf,
-    dbpath: PathBuf,
     dbconn: Option<rusqlite::Connection>,
     inited: bool,
     sender: npc_fwk::toolkit::Sender<LibNotification>,
@@ -99,7 +98,6 @@ impl Library {
         let (sender, _) = async_channel::unbounded();
         let mut lib = Library {
             // maindir: dir,
-            dbpath: PathBuf::default(),
             dbconn: None,
             inited: false,
             sender,
@@ -126,7 +124,6 @@ impl Library {
         }
         let mut lib = Library {
             // maindir: dir,
-            dbpath: dbpath.clone(),
             dbconn: None,
             inited: false,
             sender,
@@ -181,14 +178,6 @@ impl Library {
         Ok(())
     }
 
-    fn dbpath(&self) -> &Path {
-        &self.dbpath
-    }
-
-    fn is_ok(&self) -> bool {
-        self.inited
-    }
-
     fn check_database_version(&self) -> Result<i32> {
         if let Some(ref conn) = self.dbconn {
             if let Ok(mut stmt) = conn.prepare("SELECT value FROM admin WHERE key='version'") {
diff --git a/crates/npc-engine/src/library/notification.rs b/crates/npc-engine/src/library/notification.rs
index 40f8ad4..351f1f3 100644
--- a/crates/npc-engine/src/library/notification.rs
+++ b/crates/npc-engine/src/library/notification.rs
@@ -166,6 +166,8 @@ pub unsafe extern "C" fn engine_library_notification_delete(n: *mut LibNotificat
     Box::from_raw(n);
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_type(
     n: *const LibNotification,
@@ -198,6 +200,8 @@ pub unsafe extern "C" fn engine_library_notification_type(
     }
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_id(
     n: *const LibNotification,
@@ -212,6 +216,8 @@ pub unsafe extern "C" fn engine_library_notification_get_id(
     }
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_label(
     n: *const LibNotification,
@@ -224,6 +230,8 @@ pub unsafe extern "C" fn engine_library_notification_get_label(
     }
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_libmetadata(
     n: *const LibNotification,
@@ -234,6 +242,8 @@ pub unsafe extern "C" fn engine_library_notification_get_libmetadata(
     }
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_count(
     n: *const LibNotification,
@@ -247,6 +257,8 @@ pub unsafe extern "C" fn engine_library_notification_get_count(
     }
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_libfolder(
     n: *const LibNotification,
@@ -257,6 +269,8 @@ pub unsafe extern "C" fn engine_library_notification_get_libfolder(
     }
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_keyword(
     n: *const LibNotification,
diff --git a/niepce-main/src/libraryclient.rs b/niepce-main/src/libraryclient.rs
index ff4119a..b37e356 100644
--- a/niepce-main/src/libraryclient.rs
+++ b/niepce-main/src/libraryclient.rs
@@ -204,11 +204,15 @@ pub extern "C" fn lcchannel_new(
     Box::into_raw(Box::new(PortableChannel::<LibNotification>(sender)))
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn lcchannel_delete(obj: *mut LcChannel) {
     Box::from_raw(obj);
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_new(
     path: *const c_char,
@@ -221,6 +225,8 @@ pub unsafe extern "C" fn libraryclient_new(
     )))
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_delete(obj: *mut LibraryClientWrapper) {
     Box::from_raw(obj);
@@ -254,6 +260,8 @@ pub extern "C" fn libraryclient_query_folder_content(
     client.query_folder_content(folder_id);
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_create_folder_sync(
     client: &mut LibraryClientWrapper,
@@ -336,6 +344,8 @@ pub extern "C" fn libraryclient_get_all_labels(client: &mut LibraryClientWrapper
     client.get_all_labels();
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_create_label(
     client: &mut LibraryClientWrapper,
@@ -347,6 +357,8 @@ pub unsafe extern "C" fn libraryclient_create_label(
     client.create_label(String::from(name), String::from(colour));
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_create_label_sync(
     client: &mut LibraryClientWrapper,
@@ -366,6 +378,8 @@ pub extern "C" fn libraryclient_delete_label(
     client.delete_label(label_id);
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_update_label(
     client: &mut LibraryClientWrapper,
@@ -386,6 +400,8 @@ pub extern "C" fn libraryclient_process_xmp_update_queue(
     client.process_xmp_update_queue(write_xmp);
 }
 
+/// # Safety
+/// Dereference a pointer.
 #[no_mangle]
 pub unsafe extern "C" fn libraryclient_import_files(
     client: &mut LibraryClientWrapper,
diff --git a/niepce-main/src/niepce/ui/image_grid_view.rs b/niepce-main/src/niepce/ui/image_grid_view.rs
index 70eb14d..6fa09cf 100644
--- a/niepce-main/src/niepce/ui/image_grid_view.rs
+++ b/niepce-main/src/niepce/ui/image_grid_view.rs
@@ -60,14 +60,14 @@ impl ImageGridView {
         x: f64,
         y: f64,
     ) {
-        gesture.last_event(None).map(|event| {
+        if let Some(event) = gesture.last_event(None) {
             if event.triggers_context_menu() {
                 if let Some(ref menu) = menu {
                     menu.set_pointing_to(Some(&gdk4::Rectangle::new(x as i32, y as i32, 0, 0)));
                     menu.popup();
                 }
             }
-        });
+        }
 
         if let Some((_, cell)) = icon_view.item_at_pos(x as i32, y as i32) {
             if let Ok(mut cell) = cell.downcast::<LibraryCellRenderer>() {


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