[niepce] rust: fix clippy lint warnings



commit 5cb3684d2197fc161e5206f41ef73ab09addda83
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Oct 20 09:22:01 2018 -0400

    rust: fix clippy lint warnings

 src/capi.rs                               |  6 ++--
 src/engine/db/filebundle.rs               | 20 +++++++----
 src/engine/db/fsfile.rs                   |  2 +-
 src/engine/db/keyword.rs                  | 12 +++----
 src/engine/db/label.rs                    | 12 +++----
 src/engine/db/libfile.rs                  | 14 ++++----
 src/engine/db/libfolder.rs                |  4 +--
 src/engine/db/libmetadata.rs              | 26 +++++++-------
 src/engine/db/library.rs                  | 33 +++++++++---------
 src/engine/library/commands.rs            | 16 ++++-----
 src/engine/library/notification.rs        | 57 +++++++++++++++----------------
 src/fwk/base/date.rs                      |  6 ++--
 src/fwk/base/fractions.rs                 |  2 +-
 src/fwk/base/mod.rs                       |  6 ++--
 src/fwk/base/propertybag.rs               | 31 +++++++++--------
 src/fwk/base/propertyvalue.rs             | 52 ++++++++++++++--------------
 src/fwk/base/rgbcolour.rs                 | 16 ++++-----
 src/fwk/mod.rs                            |  8 ++---
 src/fwk/toolkit/mimetype.rs               |  3 +-
 src/fwk/utils/exempi.rs                   | 33 ++++++++++--------
 src/libraryclient/clientimpl.rs           |  6 ++--
 src/libraryclient/libraryclient.rs        | 56 +++++++++++++++---------------
 src/niepce/ui/dialogs/confirm.rs          | 10 +++---
 src/niepce/ui/dialogs/requestnewfolder.rs |  6 ++--
 24 files changed, 224 insertions(+), 213 deletions(-)
---
diff --git a/src/capi.rs b/src/capi.rs
index 54d85ab..a0f5c90 100644
--- a/src/capi.rs
+++ b/src/capi.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - capi.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,6 +22,6 @@ use std::ffi::CString;
 
 /// Release the raw pointer from a CString.
 #[no_mangle]
-pub extern "C" fn rust_cstring_delete(string: *mut c_char) {
-    unsafe { CString::from_raw(string); }
+pub unsafe extern "C" fn rust_cstring_delete(string: *mut c_char) {
+    CString::from_raw(string);
 }
diff --git a/src/engine/db/filebundle.rs b/src/engine/db/filebundle.rs
index 055831b..83486cd 100644
--- a/src/engine/db/filebundle.rs
+++ b/src/engine/db/filebundle.rs
@@ -40,12 +40,12 @@ pub enum Sidecar {
 
 impl Sidecar {
     pub fn to_int(&self) -> i32 {
-        match self {
-            &Sidecar::Live(_) => 1,
-            &Sidecar::Thumbnail(_) => 2,
-            &Sidecar::Xmp(_) => 3,
-            &Sidecar::Jpeg(_) => 4,
-            &Sidecar::Invalid => 0,
+        match *self {
+            Sidecar::Live(_) => 1,
+            Sidecar::Thumbnail(_) => 2,
+            Sidecar::Xmp(_) => 3,
+            Sidecar::Jpeg(_) => 4,
+            Sidecar::Invalid => 0,
         }
     }
 }
@@ -77,6 +77,12 @@ pub struct FileBundle {
     sidecars: Vec<Sidecar>,
 }
 
+impl Default for FileBundle {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 /// A file bundle represent files that are together based on their
 /// basename.
 impl FileBundle {
@@ -92,7 +98,7 @@ impl FileBundle {
 
     /// Filter the file list and turn them to bundles
     ///
-    pub fn filter_bundles(files: &Vec<String>) -> Vec<FileBundle> {
+    pub fn filter_bundles(files: &[String]) -> Vec<FileBundle> {
         let mut bundles: Vec<FileBundle> = vec![];
         let mut sorted_files: Vec<&String> = files.iter().collect();
         sorted_files.sort();
diff --git a/src/engine/db/fsfile.rs b/src/engine/db/fsfile.rs
index 493706a..95de96d 100644
--- a/src/engine/db/fsfile.rs
+++ b/src/engine/db/fsfile.rs
@@ -31,7 +31,7 @@ impl FsFile {
 
     pub fn new(id: LibraryId, path: PathBuf) -> FsFile {
         FsFile {
-            id: id, path: path,
+            id, path,
         }
     }
 
diff --git a/src/engine/db/keyword.rs b/src/engine/db/keyword.rs
index 556064a..08dc0c4 100644
--- a/src/engine/db/keyword.rs
+++ b/src/engine/db/keyword.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - engine/db/keyword.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ pub struct Keyword {
 impl Keyword {
     pub fn new(id: LibraryId, keyword: &str) -> Keyword {
         Keyword {
-            id: id, keyword: String::from(keyword),
+            id, keyword: String::from(keyword),
         }
     }
 
@@ -65,8 +65,8 @@ impl FromDb for Keyword {
 }
 
 #[no_mangle]
-pub extern fn engine_db_keyword_new(id: i64, keyword: *const c_char) -> *mut Keyword {
-    let kw = Box::new(Keyword::new(id, &*unsafe { CStr::from_ptr(keyword) }.to_string_lossy()));
+pub unsafe extern fn engine_db_keyword_new(id: i64, keyword: *const c_char) -> *mut Keyword {
+    let kw = Box::new(Keyword::new(id, &*CStr::from_ptr(keyword).to_string_lossy()));
     Box::into_raw(kw)
 }
 
@@ -82,6 +82,6 @@ pub extern fn engine_db_keyword_keyword(obj: &Keyword) -> *mut c_char {
 }
 
 #[no_mangle]
-pub extern fn engine_db_keyword_delete(kw: *mut Keyword) {
-    unsafe { Box::from_raw(kw) };
+pub unsafe extern fn engine_db_keyword_delete(kw: *mut Keyword) {
+    Box::from_raw(kw);
 }
diff --git a/src/engine/db/label.rs b/src/engine/db/label.rs
index afb7854..22bf63a 100644
--- a/src/engine/db/label.rs
+++ b/src/engine/db/label.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - engine/db/label.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,12 +37,12 @@ pub struct Label {
 impl Label {
 
     pub fn new(id: LibraryId, label: &str, colourstring: &str) -> Label {
-        let colour = RgbColour::from_str(colourstring).unwrap_or(Default::default());
+        let colour = RgbColour::from_str(colourstring).unwrap_or_default();
         Label {
-            id: id,
+            id,
             label: String::from(label),
             cstr: CString::new("").unwrap(),
-            colour: colour
+            colour,
         }
     }
 
@@ -89,8 +89,8 @@ impl FromDb for Label {
 
 
 #[no_mangle]
-pub extern fn engine_db_label_delete(l: *mut Label) {
-    unsafe { Box::from_raw(l) };
+pub unsafe extern fn engine_db_label_delete(l: *mut Label) {
+    Box::from_raw(l);
 }
 
 #[no_mangle]
diff --git a/src/engine/db/libfile.rs b/src/engine/db/libfile.rs
index ae45e2c..23586d8 100644
--- a/src/engine/db/libfile.rs
+++ b/src/engine/db/libfile.rs
@@ -96,10 +96,10 @@ impl LibFile {
                path: PathBuf, name: &str) -> LibFile {
         let main_file = FsFile::new(fs_file_id, path);
         LibFile {
-            id: id, folder_id: folder_id,
+            id, folder_id,
             name: String::from(name),
             cstr: CString::new("").unwrap(),
-            main_file: main_file, orientation: 0,
+            main_file, orientation: 0,
             rating: 0, label: 0, flag: 0,
             file_type: FileType::UNKNOWN,
         }
@@ -246,20 +246,20 @@ pub fn mimetype_to_filetype(mime: &fwk::MimeType) -> FileType {
 }
 
 #[no_mangle]
-pub extern fn engine_db_libfile_new(id: LibraryId, folder_id: LibraryId,
+pub unsafe extern fn engine_db_libfile_new(id: LibraryId, folder_id: LibraryId,
                                     fs_file_id: LibraryId, path: *const c_char,
                                     name: *const c_char) -> *mut LibFile {
     let lf = Box::new(
         LibFile::new(id, folder_id, fs_file_id,
-                     PathBuf::from(&*unsafe { CStr::from_ptr(path) }.to_string_lossy()),
-                     &*unsafe { CStr::from_ptr(name) }.to_string_lossy())
+                     PathBuf::from(&*CStr::from_ptr(path).to_string_lossy()),
+                     &*CStr::from_ptr(name).to_string_lossy())
             );
     Box::into_raw(lf)
 }
 
 #[no_mangle]
-pub extern fn engine_db_libfile_delete(lf: *mut LibFile) {
-    unsafe { Box::from_raw(lf) };
+pub unsafe extern fn engine_db_libfile_delete(lf: *mut LibFile) {
+    Box::from_raw(lf);
 }
 
 #[no_mangle]
diff --git a/src/engine/db/libfolder.rs b/src/engine/db/libfolder.rs
index 9930d61..a0196e4 100644
--- a/src/engine/db/libfolder.rs
+++ b/src/engine/db/libfolder.rs
@@ -58,8 +58,8 @@ pub struct LibFolder {
 impl LibFolder {
     pub fn new(id: LibraryId, name: &str, path: Option<String>) -> LibFolder {
         LibFolder {
-            id: id, name: String::from(name),
-            path: path,
+            id, name: String::from(name),
+            path,
             locked: false,
             expanded: false, virt: FolderVirtualType::NONE,
             parent: 0,
diff --git a/src/engine/db/libmetadata.rs b/src/engine/db/libmetadata.rs
index 158627c..611fb03 100644
--- a/src/engine/db/libmetadata.rs
+++ b/src/engine/db/libmetadata.rs
@@ -59,7 +59,7 @@ impl LibMetadata {
     pub fn new(id: LibraryId) -> LibMetadata {
         LibMetadata {
             xmp: XmpMeta::new(),
-            id: id,
+            id,
             sidecars: vec![], file_type: FileType::UNKNOWN,
             name: String::new(),
             folder: String::new()
@@ -68,8 +68,8 @@ impl LibMetadata {
 
     pub fn new_with_xmp(id: LibraryId, xmp: XmpMeta) -> LibMetadata {
         LibMetadata {
-            xmp: xmp,
-            id: id,
+            xmp,
+            id,
             sidecars: vec![],
             file_type: FileType::UNKNOWN,
             name: String::new(),
@@ -111,14 +111,14 @@ impl LibMetadata {
 
     pub fn set_metadata(&mut self, meta: Np, value: &PropertyValue) -> bool {
         if let Some(ix) = property_index_to_xmp(meta) {
-            match value {
-                &PropertyValue::Empty => return self.xmp.xmp.delete_property(&ix.ns, &ix.property),
-                &PropertyValue::Int(i) => {
+            match *value {
+                PropertyValue::Empty => return self.xmp.xmp.delete_property(&ix.ns, &ix.property),
+                PropertyValue::Int(i) => {
                     return self.xmp
                         .xmp
                         .set_property_i32(&ix.ns, &ix.property, i, exempi::PROP_NONE)
                 }
-                &PropertyValue::String(ref s) => {
+                PropertyValue::String(ref s) => {
                     if s.is_empty() {
                         return self.xmp.xmp.delete_property(&ix.ns, &ix.property);
                     } else if !self.xmp
@@ -139,20 +139,20 @@ impl LibMetadata {
                         return true;
                     }
                 }
-                &PropertyValue::StringArray(ref sa) => {
+                PropertyValue::StringArray(ref sa) => {
                     self.xmp.xmp.delete_property(&ix.ns, &ix.property);
-                    for i in 0..sa.len() {
+                    for s in sa {
                         self.xmp.xmp.append_array_item(
                             &ix.ns,
                             &ix.property,
                             exempi::PROP_VALUE_IS_ARRAY,
-                            &sa[i],
+                            s,
                             exempi::PROP_NONE,
                         );
                     }
                     return true;
                 }
-                &PropertyValue::Date(ref d) => {
+                PropertyValue::Date(ref d) => {
                     let xmp_date = xmp_date_from(d);
                     return self.xmp.xmp.set_property_date(
                         &ix.ns,
@@ -243,9 +243,9 @@ impl LibMetadata {
 
     pub fn touch(&mut self) -> bool {
         let xmpdate = xmp_date_from(&Utc::now());
-        return self.xmp
+        self.xmp
             .xmp
-            .set_property_date(NS_XAP, "MetadataDate", &xmpdate, exempi::PROP_NONE);
+            .set_property_date(NS_XAP, "MetadataDate", &xmpdate, exempi::PROP_NONE)
     }
 }
 
diff --git a/src/engine/db/library.rs b/src/engine/db/library.rs
index 08aa1f5..8f00e1c 100644
--- a/src/engine/db/library.rs
+++ b/src/engine/db/library.rs
@@ -95,8 +95,8 @@ impl Library {
         lib
     }
 
-    pub fn new(dir: PathBuf, name: Option<&str>, notif_id: u64) -> Library {
-        let mut dbpath = dir.clone();
+    pub fn new(dir: &Path, name: Option<&str>, notif_id: u64) -> Library {
+        let mut dbpath = PathBuf::from(dir);
         if let Some(filename) = name {
             dbpath.push(filename);
         } else {
@@ -323,11 +323,11 @@ impl Library {
     }
 
     pub fn add_sidecar_file_to_bundle(&self, file_id: LibraryId, sidecar: &Sidecar) -> Result<()> {
-        let sidecar_t: (i32, &String) = match sidecar {
-            &Sidecar::Live(ref p)
-            | &Sidecar::Thumbnail(ref p)
-            | &Sidecar::Xmp(ref p)
-            | &Sidecar::Jpeg(ref p) => (sidecar.to_int(), p),
+        let sidecar_t: (i32, &String) = match *sidecar {
+            Sidecar::Live(ref p)
+            | Sidecar::Thumbnail(ref p)
+            | Sidecar::Xmp(ref p)
+            | Sidecar::Jpeg(ref p) => (sidecar.to_int(), p),
             _ => return Err(Error::InvalidArg),
         };
         let p = Path::new(sidecar_t.1);
@@ -424,12 +424,11 @@ impl Library {
 
     pub fn delete_folder(&self, id: LibraryId) -> Result<()> {
         if let Some(ref conn) = self.dbconn {
-            if let Some(c) = conn.execute("DELETE FROM folders WHERE id=?1", &[&id]).ok() {
-                if c == 1 {
-                    return Ok(());;
-                }
-                return Err(Error::InvalidResult);
+            let c = conn.execute("DELETE FROM folders WHERE id=?1", &[&id])?;
+            if c == 1 {
+                return Ok(());;
             }
+            return Err(Error::InvalidResult);
         }
         Err(Error::NoSqlDb)
     }
@@ -625,7 +624,7 @@ impl Library {
             xmp = String::from("");
         }
 
-        let filename = Self::leaf_name_for_pathname(file).unwrap_or(String::from(""));
+        let filename = Self::leaf_name_for_pathname(file).unwrap_or_default();
         let fs_file_id = self.add_fs_file(file)?;
         if fs_file_id <= 0 {
             err_out!("add fsfile failed");
@@ -835,8 +834,8 @@ impl Library {
             Np::NpIptcKeywordsProp => {
                 self.unassign_all_keywords_for_file(file_id)?;
 
-                match value {
-                    &PropertyValue::StringArray(ref keywords) =>
+                match *value {
+                    PropertyValue::StringArray(ref keywords) =>
                         for kw in keywords {
                             let id = self.make_keyword(&kw)?;
                             if id != -1 {
@@ -961,7 +960,7 @@ impl Library {
         // 3. make sure the update happened correctly, possibly ensure we don't
         // clobber the xmp.
         if let Some(ref conn) = self.dbconn {
-            if let Ok(_) = conn.execute("DELETE FROM xmp_update_queue WHERE id=?1;", &[&id]) {
+            if conn.execute("DELETE FROM xmp_update_queue WHERE id=?1;", &[&id]).is_ok() {
                 // we don't want to write the XMP so we don't need to list them.
                 if !write_xmp {
                     return Ok(());
@@ -1029,7 +1028,7 @@ impl Library {
             self.rewrite_xmp_for_id(id, write_xmp)?;
         }
 
-        return Ok(());
+        Ok(())
     }
 }
 
diff --git a/src/engine/library/commands.rs b/src/engine/library/commands.rs
index 62c803b..c75f099 100644
--- a/src/engine/library/commands.rs
+++ b/src/engine/library/commands.rs
@@ -103,7 +103,7 @@ fn get_folder_for_import(lib: &Library, folder: &str) -> library::Result<LibFold
     }
 }
 
-pub fn cmd_import_files(lib: &Library, folder: &str, files: &Vec<String>,
+pub fn cmd_import_files(lib: &Library, folder: &str, files: &[String],
                         manage: Managed) -> bool {
     dbg_assert!(manage == Managed::NO, "managing file is currently unsupported");
 
@@ -112,7 +112,7 @@ pub fn cmd_import_files(lib: &Library, folder: &str, files: &Vec<String>,
         Ok(libfolder) =>  {
             let folder_id = libfolder.id();
             for bundle in bundles {
-                if let Err(err) = lib.add_bundle(folder_id, &bundle, manage.clone()) {
+                if let Err(err) = lib.add_bundle(folder_id, &bundle, manage) {
                     err_out!("Add bundle failed: {:?}", err);
                 }
             }
@@ -126,7 +126,7 @@ pub fn cmd_import_files(lib: &Library, folder: &str, files: &Vec<String>,
     }
 }
 
-pub fn cmd_create_folder(lib: &Library, name: &String, path: Option<String>) -> LibraryId {
+pub fn cmd_create_folder(lib: &Library, name: &str, path: Option<String>) -> LibraryId {
     match lib.add_folder(name, path) {
         Ok(lf) =>  {
             let id = lf.id();
@@ -201,11 +201,11 @@ pub fn cmd_set_metadata(lib: &Library, id: LibraryId, meta: Np,
     }
 }
 
-pub fn cmd_count_folder(lib: &Library, folder_id: LibraryId) -> bool {
-    match lib.count_folder(folder_id) {
+pub fn cmd_count_folder(lib: &Library, id: LibraryId) -> bool {
+    match lib.count_folder(id) {
         Ok(count) => {
             lib.notify(Box::new(LibNotification::FolderCounted(
-                Count{id: folder_id, count: count})));
+                Count{id, count})));
             true
         },
         Err(err) => {
@@ -249,7 +249,7 @@ pub fn cmd_count_keyword(lib: &Library, id: LibraryId) -> bool {
     match lib.count_keyword(id) {
         Ok(count) => {
             lib.notify(Box::new(LibNotification::KeywordCounted(
-                Count{id: id, count: count})));
+                Count{id, count})));
             true
         },
         Err(err) => {
@@ -274,7 +274,7 @@ pub fn cmd_move_file_to_folder(lib: &Library, file_id: LibraryId, from: LibraryI
     match lib.move_file_to_folder(file_id, to) {
         Ok(_) => {
             lib.notify(Box::new(LibNotification::FileMoved(
-                FileMove{file: file_id, from: from, to: to})));
+                FileMove{file: file_id, from, to})));
             lib.notify(Box::new(LibNotification::FolderCountChanged(
                 Count{id: from, count: -1})));
             lib.notify(Box::new(LibNotification::FolderCountChanged(
diff --git a/src/engine/library/notification.rs b/src/engine/library/notification.rs
index 3156198..286d94c 100644
--- a/src/engine/library/notification.rs
+++ b/src/engine/library/notification.rs
@@ -85,7 +85,7 @@ pub struct MetadataChange {
 
 impl MetadataChange {
     pub fn new(id: LibraryId, meta: PropertyIndex, value: Box<PropertyValue>) -> Self {
-        MetadataChange {id: id, meta: meta, value: Box::into_raw(value)}
+        MetadataChange {id, meta, value: Box::into_raw(value)}
     }
 }
 
@@ -146,23 +146,23 @@ pub unsafe fn engine_library_notify(_: u64, _: *mut Notification) {
 
 /// Send a notification for the file status change.
 #[no_mangle]
-pub extern "C" fn engine_library_notify_filestatus_changed(notif_id: u64,
+pub unsafe extern "C" fn engine_library_notify_filestatus_changed(notif_id: u64,
                                                            id: LibraryId,
                                                            status: FileStatus) {
     let notif = Box::new(Notification::FileStatusChanged(
         FileStatusChange{id, status}));
-    unsafe { engine_library_notify(notif_id, Box::into_raw(notif)) }
+    engine_library_notify(notif_id, Box::into_raw(notif));
 }
 
 /// Delete the Notification object.
 #[no_mangle]
-pub extern "C" fn engine_library_notification_delete(n: *mut Notification) {
-    unsafe { Box::from_raw(n); }
+pub unsafe extern "C" fn engine_library_notification_delete(n: *mut Notification) {
+    Box::from_raw(n);
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_type(n: *const Notification) -> NotificationType {
-    let t = match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_type(n: *const Notification) -> NotificationType {
+    match n.as_ref() {
         Some(&Notification::AddedFile) => NotificationType::ADDED_FILE,
         Some(&Notification::AddedFiles) => NotificationType::ADDED_FILES,
         Some(&Notification::AddedFolder(_)) => NotificationType::ADDED_FOLDER,
@@ -185,14 +185,13 @@ pub extern "C" fn engine_library_notification_type(n: *const Notification) -> No
         Some(&Notification::MetadataQueried(_)) => NotificationType::METADATA_QUERIED,
         Some(&Notification::XmpNeedsUpdate) => NotificationType::XMP_NEEDS_UPDATE,
         None => unreachable!(),
-    };
-    t
+    }
 }
 
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_id(n: *const Notification) -> LibraryId {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_id(n: *const Notification) -> LibraryId {
+    match n.as_ref() {
         Some(&Notification::MetadataChanged(ref changed)) => changed.id,
         Some(&Notification::FolderDeleted(id)) => id,
         Some(&Notification::LabelDeleted(id)) => id,
@@ -202,8 +201,8 @@ pub extern "C" fn engine_library_notification_get_id(n: *const Notification) ->
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_label(n: *const Notification) -> *const Label {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_label(n: *const Notification) -> *const Label {
+    match n.as_ref() {
         Some(&Notification::AddedLabel(ref l)) |
         Some(&Notification::LabelChanged(ref l)) => l,
         _ => unreachable!(),
@@ -211,32 +210,32 @@ pub extern "C" fn engine_library_notification_get_label(n: *const Notification)
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_filemoved(n: *const Notification) -> *const FileMove {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_filemoved(n: *const Notification) -> *const 
FileMove {
+    match n.as_ref() {
         Some(&Notification::FileMoved(ref m)) => m,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_filestatus(n: *const Notification) -> FileStatus {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_filestatus(n: *const Notification) -> FileStatus {
+    match n.as_ref() {
         Some(&Notification::FileStatusChanged(ref s)) => s.status,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_libmetadata(n: *const Notification) -> *const LibMetadata {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_libmetadata(n: *const Notification) -> *const 
LibMetadata {
+    match n.as_ref() {
         Some(&Notification::MetadataQueried(ref m)) => m,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_count(n: *const Notification) -> *const Count {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_count(n: *const Notification) -> *const Count {
+    match n.as_ref() {
         Some(&Notification::FolderCountChanged(ref c)) |
         Some(&Notification::FolderCounted(ref c)) |
         Some(&Notification::KeywordCountChanged(ref c)) |
@@ -247,32 +246,32 @@ pub extern "C" fn engine_library_notification_get_count(n: *const Notification)
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_metadatachange(n: *const Notification) -> *const 
MetadataChange {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_metadatachange(n: *const Notification) -> *const 
MetadataChange {
+    match n.as_ref() {
         Some(&Notification::MetadataChanged(ref c)) => c,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_libfolder(n: *const Notification) -> *const LibFolder {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_libfolder(n: *const Notification) -> *const 
LibFolder {
+    match n.as_ref() {
         Some(&Notification::AddedFolder(ref f)) => f,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_keyword(n: *const Notification) -> *const Keyword {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_keyword(n: *const Notification) -> *const Keyword {
+    match n.as_ref() {
         Some(&Notification::AddedKeyword(ref f)) => f,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn engine_library_notification_get_content(n: *const Notification) -> *const Content {
-    match unsafe { n.as_ref() } {
+pub unsafe extern "C" fn engine_library_notification_get_content(n: *const Notification) -> *const Content {
+    match n.as_ref() {
         Some(&Notification::FolderContentQueried(ref c)) |
         Some(&Notification::KeywordContentQueried(ref c)) => {
             c
diff --git a/src/fwk/base/date.rs b/src/fwk/base/date.rs
index 2d51817..0645047 100644
--- a/src/fwk/base/date.rs
+++ b/src/fwk/base/date.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/base/date.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -44,8 +44,8 @@ pub fn xmp_date_from(d: &chrono::DateTime<chrono::Utc>) -> exempi::DateTime {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_date_delete(date: *mut Date) {
-    unsafe { Box::from_raw(date); }
+pub unsafe extern "C" fn fwk_date_delete(date: *mut Date) {
+    Box::from_raw(date);
 }
 
 #[no_mangle]
diff --git a/src/fwk/base/fractions.rs b/src/fwk/base/fractions.rs
index 8c1c6fb..aa8e1bc 100644
--- a/src/fwk/base/fractions.rs
+++ b/src/fwk/base/fractions.rs
@@ -22,7 +22,7 @@ use std::f64;
 
 pub fn fraction_to_decimal(value: &str) -> Option<f64>
 {
-    let numbers: Vec<i64> = value.split("/")
+    let numbers: Vec<i64> = value.split('/')
         .map(|s| { s.parse::<i64>().unwrap_or(0) })
         .collect();
     if numbers.len() != 2 {
diff --git a/src/fwk/base/mod.rs b/src/fwk/base/mod.rs
index fa80025..e0a2f09 100644
--- a/src/fwk/base/mod.rs
+++ b/src/fwk/base/mod.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/base/mod.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,8 +39,8 @@ pub extern "C" fn fwk_property_set_new() -> *mut PropertySet {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_set_delete(set: *mut PropertySet) {
-    unsafe { Box::from_raw(set); }
+pub unsafe extern "C" fn fwk_property_set_delete(set: *mut PropertySet) {
+    Box::from_raw(set);
 }
 
 #[no_mangle]
diff --git a/src/fwk/base/propertybag.rs b/src/fwk/base/propertybag.rs
index 2f6c33b..8c47cec 100644
--- a/src/fwk/base/propertybag.rs
+++ b/src/fwk/base/propertybag.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/base/propertybag.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@ use std::ptr;
 use fwk::base::PropertyIndex;
 use fwk::base::propertyvalue::PropertyValue;
 
+#[derive(Default)]
 pub struct PropertyBag {
     pub bag: Vec<PropertyIndex>,
     pub map: BTreeMap<PropertyIndex, PropertyValue>,
@@ -31,7 +32,7 @@ pub struct PropertyBag {
 impl PropertyBag {
 
     pub fn new() -> Self {
-        PropertyBag{ bag: Vec::new(), map: BTreeMap::new() }
+        PropertyBag::default()
     }
 
     pub fn is_empty(&self) -> bool {
@@ -58,39 +59,39 @@ pub extern "C" fn fwk_property_bag_new() -> *mut PropertyBag {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_bag_delete(bag: *mut PropertyBag) {
-    unsafe { Box::from_raw(bag); }
+pub unsafe extern "C" fn fwk_property_bag_delete(bag: *mut PropertyBag) {
+    Box::from_raw(bag);
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_bag_is_empty(b: *const PropertyBag) -> bool {
-    match unsafe { b.as_ref() } {
+pub unsafe extern "C" fn fwk_property_bag_is_empty(b: *const PropertyBag) -> bool {
+    match b.as_ref() {
         Some(ref pb) => pb.is_empty(),
         None => true
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_bag_len(b: *const PropertyBag) -> usize {
-    match unsafe { b.as_ref() } {
+pub unsafe extern "C" fn fwk_property_bag_len(b: *const PropertyBag) -> usize {
+    match b.as_ref() {
         Some(ref pb) => pb.len(),
         None => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_bag_key_by_index(b: *const PropertyBag, idx: usize)
+pub unsafe extern "C" fn fwk_property_bag_key_by_index(b: *const PropertyBag, idx: usize)
                                          -> PropertyIndex {
-    match unsafe { b.as_ref() } {
+    match b.as_ref() {
         Some(ref pb) => pb.bag[idx],
         None => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_bag_value(b: *const PropertyBag, key: PropertyIndex)
+pub unsafe extern "C" fn fwk_property_bag_value(b: *const PropertyBag, key: PropertyIndex)
                                          -> *mut PropertyValue {
-    match unsafe { b.as_ref() } {
+    match b.as_ref() {
         Some(ref pb) => {
             if pb.map.contains_key(&key) {
                 let value = Box::new(pb.map[&key].clone());
@@ -104,13 +105,13 @@ pub extern "C" fn fwk_property_bag_value(b: *const PropertyBag, key: PropertyInd
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_bag_set_value(b: *mut PropertyBag, key: PropertyIndex,
+pub unsafe extern "C" fn fwk_property_bag_set_value(b: *mut PropertyBag, key: PropertyIndex,
                                              v: *const PropertyValue) -> bool {
-    let value = match unsafe { v.as_ref() } {
+    let value = match v.as_ref() {
         Some(value) => value.clone(),
         None => unreachable!()
     };
-    match unsafe { b.as_mut() } {
+    match b.as_mut() {
         Some(ref mut pb) => {
             pb.set_value(key, value)
         },
diff --git a/src/fwk/base/propertyvalue.rs b/src/fwk/base/propertyvalue.rs
index 78ee385..fb80cca 100644
--- a/src/fwk/base/propertyvalue.rs
+++ b/src/fwk/base/propertyvalue.rs
@@ -35,8 +35,8 @@ impl PropertyValue {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_new_str(v: *const c_char) -> *mut PropertyValue {
-    let cstr = unsafe { CStr::from_ptr(v) };
+pub unsafe extern "C" fn fwk_property_value_new_str(v: *const c_char) -> *mut PropertyValue {
+    let cstr = CStr::from_ptr(v);
     let value = Box::new(PropertyValue::String(cstr.to_string_lossy().into_owned()));
     Box::into_raw(value)
 }
@@ -49,7 +49,7 @@ pub extern "C" fn fwk_property_value_new_int(v: i32) -> *mut PropertyValue {
 
 #[no_mangle]
 pub extern "C" fn fwk_property_value_new_date(v: &Date) -> *mut PropertyValue {
-    let value = Box::new(PropertyValue::Date(v.clone()));
+    let value = Box::new(PropertyValue::Date(*v));
     Box::into_raw(value)
 }
 
@@ -60,63 +60,63 @@ pub extern "C" fn fwk_property_value_new_string_array() -> *mut PropertyValue {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_delete(v: *mut PropertyValue) {
+pub unsafe extern "C" fn fwk_property_value_delete(v: *mut PropertyValue) {
     if !v.is_null() {
-        unsafe { Box::from_raw(v); }
+        Box::from_raw(v);
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_is_empty(v: *const PropertyValue) -> bool {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_is_empty(v: *const PropertyValue) -> bool {
+    match v.as_ref() {
         Some(&PropertyValue::Empty) => true,
         _ => false
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_is_integer(v: *const PropertyValue) -> bool {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_is_integer(v: *const PropertyValue) -> bool {
+    match v.as_ref() {
         Some(&PropertyValue::Int(_)) => true,
         _ => false
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_get_integer(v: *const PropertyValue) -> i32 {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_get_integer(v: *const PropertyValue) -> i32 {
+    match v.as_ref() {
         Some(&PropertyValue::Int(i)) => i,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_is_date(v: *const PropertyValue) -> bool {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_is_date(v: *const PropertyValue) -> bool {
+    match v.as_ref() {
         Some(&PropertyValue::Date(_)) => true,
         _ => false
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_get_date(v: *const PropertyValue) -> *const Date {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_get_date(v: *const PropertyValue) -> *const Date {
+    match v.as_ref() {
         Some(&PropertyValue::Date(ref d)) => d,
         _ => unreachable!()
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_is_string(v: *const PropertyValue) -> bool {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_is_string(v: *const PropertyValue) -> bool {
+    match v.as_ref() {
         Some(&PropertyValue::String(_)) => true,
         _ => false
     }
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_get_string(v: *const PropertyValue) -> *mut c_char {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_get_string(v: *const PropertyValue) -> *mut c_char {
+    match v.as_ref() {
         Some(&PropertyValue::String(ref s)) => {
             CString::new(s.as_bytes()).unwrap().into_raw()
         },
@@ -125,10 +125,10 @@ pub extern "C" fn fwk_property_value_get_string(v: *const PropertyValue) -> *mut
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_add_string(v: *mut PropertyValue, str: *const c_char) {
-    match unsafe { v.as_mut() } {
+pub unsafe extern "C" fn fwk_property_value_add_string(v: *mut PropertyValue, str: *const c_char) {
+    match v.as_mut() {
         Some(&mut PropertyValue::StringArray(ref mut sa)) => {
-            sa.push(unsafe { CStr::from_ptr(str) }.to_string_lossy().into_owned());
+            sa.push(CStr::from_ptr(str).to_string_lossy().into_owned());
         },
         _ => unreachable!()
     }
@@ -136,8 +136,8 @@ pub extern "C" fn fwk_property_value_add_string(v: *mut PropertyValue, str: *con
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_count_string_array(v: *const PropertyValue) -> usize {
-    match unsafe { v.as_ref() } {
+pub unsafe extern "C" fn fwk_property_value_count_string_array(v: *const PropertyValue) -> usize {
+    match v.as_ref() {
         Some(&PropertyValue::StringArray(ref sa)) => {
             sa.len()
         },
@@ -146,9 +146,9 @@ pub extern "C" fn fwk_property_value_count_string_array(v: *const PropertyValue)
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_property_value_get_string_at(v: *const PropertyValue, idx: usize)
+pub unsafe extern "C" fn fwk_property_value_get_string_at(v: *const PropertyValue, idx: usize)
                                                    -> *mut c_char {
-    match unsafe { v.as_ref() } {
+    match v.as_ref() {
         Some(&PropertyValue::StringArray(ref sa)) => {
             CString::new(sa[idx].as_bytes()).unwrap().into_raw()
         },
diff --git a/src/fwk/base/rgbcolour.rs b/src/fwk/base/rgbcolour.rs
index 29979c5..0bb11df 100644
--- a/src/fwk/base/rgbcolour.rs
+++ b/src/fwk/base/rgbcolour.rs
@@ -49,7 +49,7 @@ impl From<ParseIntError> for ColourParseError {
 impl RgbColour {
 
     pub fn new(r: u16, g: u16, b: u16) -> RgbColour {
-        RgbColour{r: r, g: g, b: b}
+        RgbColour{r, g, b}
     }
 }
 
@@ -58,13 +58,13 @@ impl FromStr for RgbColour {
     type Err = ColourParseError;
 
     fn from_str(s: &str) -> Result<Self, Self::Err> {
-        let v: Vec<&str> = s.split(' ').collect();
-        if v.len() != 3 {
+        let components: Vec<&str> = s.split(' ').collect();
+        if components.len() != 3 {
             return Err(ColourParseError::ParseError);
         }
-        let r = u16::from_str_radix(v[0], 10)?;
-        let g = u16::from_str_radix(v[1], 10)?;
-        let b = u16::from_str_radix(v[2], 10)?;
+        let r = u16::from_str_radix(components[0], 10)?;
+        let g = u16::from_str_radix(components[1], 10)?;
+        let b = u16::from_str_radix(components[2], 10)?;
         Ok(RgbColour::new(r, g, b))
     }
 }
@@ -81,8 +81,8 @@ pub extern "C" fn fwk_rgbcolour_to_string(c: &RgbColour) -> *mut c_char {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_rgbcolour_delete(c: *mut RgbColour) {
-    unsafe { Box::from_raw(c); }
+pub unsafe extern "C" fn fwk_rgbcolour_delete(c: *mut RgbColour) {
+    Box::from_raw(c);
 }
 
 #[no_mangle]
diff --git a/src/fwk/mod.rs b/src/fwk/mod.rs
index 1321fd5..0c8d2d5 100644
--- a/src/fwk/mod.rs
+++ b/src/fwk/mod.rs
@@ -46,8 +46,8 @@ use std::ffi::CStr;
 use libc::c_char;
 
 #[no_mangle]
-pub extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
-    let value = unsafe { CStr::from_ptr(cvalue) };
+pub unsafe extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
+    let value = CStr::from_ptr(cvalue);
     if let Ok(svalue) = value.to_str() {
         if let Some(coord) = gps_coord_from_xmp(svalue) {
             return coord;
@@ -57,8 +57,8 @@ pub extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_fraction_to_decimal(cvalue: *const c_char) -> f64 {
-    let value = unsafe { CStr::from_ptr(cvalue) };
+pub unsafe extern "C" fn fwk_fraction_to_decimal(cvalue: *const c_char) -> f64 {
+    let value = CStr::from_ptr(cvalue);
     if let Ok(svalue) = value.to_str() {
         if let Some(dec) = fraction_to_decimal(svalue) {
             return dec;
diff --git a/src/fwk/toolkit/mimetype.rs b/src/fwk/toolkit/mimetype.rs
index 8c8d449..0d55477 100644
--- a/src/fwk/toolkit/mimetype.rs
+++ b/src/fwk/toolkit/mimetype.rs
@@ -83,8 +83,9 @@ fn guess_type_for_file(filename: &str) -> MType {
     // alternative
     let mut uncertainty: gboolean = 0;
     let content_type = unsafe {
+        let cstr = CString::new(filename).unwrap();
         gio_sys::g_content_type_guess(
-            CString::new(filename).unwrap().as_ptr(),
+            cstr.as_ptr(),
             ptr::null_mut(),
             0,
             &mut uncertainty,
diff --git a/src/fwk/utils/exempi.rs b/src/fwk/utils/exempi.rs
index eca2444..eee3828 100644
--- a/src/fwk/utils/exempi.rs
+++ b/src/fwk/utils/exempi.rs
@@ -67,6 +67,11 @@ pub struct XmpMeta {
     keywords_fetched: bool,
 }
 
+impl Default for XmpMeta {
+    fn default() -> XmpMeta {
+        XmpMeta::new()
+    }
+}
 
 impl XmpMeta {
     pub fn new() -> XmpMeta {
@@ -83,7 +88,7 @@ impl XmpMeta {
             if let Some(xmpfile) = exempi::XmpFile::open_new(file, exempi::OPEN_READ) {
                 if let Some(xmp) = xmpfile.get_new_xmp() {
                     meta = Some(XmpMeta {
-                        xmp: xmp,
+                        xmp,
                         keywords: Vec::new(),
                         keywords_fetched: false
                     });
@@ -95,14 +100,14 @@ impl XmpMeta {
         let filepath = Path::new(file);
         let sidecar = filepath.with_extension("xmp");
         let sidecaropen = File::open(sidecar);
-        if let Some(mut sidecarfile) = sidecaropen.ok() {
+        if let Ok(mut sidecarfile) = sidecaropen {
             let mut sidecarcontent = String::new();
             let result = sidecarfile.read_to_string(&mut sidecarcontent);
             if result.ok().is_some() {
                 let mut xmp = exempi::Xmp::new();
                 if xmp.parse(sidecarcontent.into_bytes().as_slice()) {
                     sidecar_meta = Some(XmpMeta {
-                        xmp: xmp,
+                        xmp,
                         keywords: Vec::new(),
                         keywords_fetched: false
                     });
@@ -200,7 +205,7 @@ impl XmpMeta {
 
     pub fn orientation(&self) -> Option<i32> {
         let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
-        return self.xmp.get_property_i32(NS_TIFF, "Orientation", &mut flags);
+        self.xmp.get_property_i32(NS_TIFF, "Orientation", &mut flags)
     }
 
     pub fn label(&self) -> Option<String> {
@@ -211,12 +216,12 @@ impl XmpMeta {
 
     pub fn rating(&self) -> Option<i32> {
         let mut flags: exempi::PropFlags = exempi::PROP_NONE;
-        return self.xmp.get_property_i32(NS_XAP, "Rating", &mut flags);
+        self.xmp.get_property_i32(NS_XAP, "Rating", &mut flags)
     }
 
     pub fn flag(&self) -> Option<i32> {
         let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
-        return self.xmp.get_property_i32(NIEPCE_XMP_NAMESPACE, "Flag", &mut flags);
+        self.xmp.get_property_i32(NIEPCE_XMP_NAMESPACE, "Flag", &mut flags)
     }
 
     pub fn creation_date(&self) -> Option<DateTime<Utc>> {
@@ -224,7 +229,7 @@ impl XmpMeta {
         let xmpstring = try_opt!(self.xmp.get_property(NS_EXIF, "DateTimeOriginal", &mut flags));
         let date = try_opt!(DateTime::parse_from_rfc3339(xmpstring.to_str()).ok());
 
-        return Some(date.with_timezone(&Utc));
+        Some(date.with_timezone(&Utc))
     }
 
     pub fn creation_date_str(&self) -> Option<String> {
@@ -239,14 +244,14 @@ impl XmpMeta {
         let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
         let xmpstring = try_opt!(self.xmp.get_property(ns, property, &mut flags));
         let date = try_opt!(DateTime::parse_from_rfc3339(xmpstring.to_str()).ok());
-        return Some(date.with_timezone(&Utc));
+        Some(date.with_timezone(&Utc))
     }
 
     pub fn keywords(&mut self) -> &Vec<String> {
         if !self.keywords_fetched {
             use exempi::XmpString;
 
-            let mut iter = exempi::XmpIterator::new(&mut self.xmp, NS_DC, "subject",
+            let mut iter = exempi::XmpIterator::new(&self.xmp, NS_DC, "subject",
                                                     exempi::ITER_JUST_LEAF_NODES);
             let mut schema = XmpString::new();
             let mut name = XmpString::new();
@@ -272,7 +277,7 @@ pub fn gps_coord_from_xmp(xmps: &str) -> Option<f64> {
     degs = d;
 
     // step 2 - minutes
-    if current.len() < 1 {
+    if current.is_empty() {
         return None;
     }
     // get rid of the comma
@@ -315,17 +320,17 @@ pub fn gps_coord_from_xmp(xmps: &str) -> Option<f64> {
     deg += fminutes / 60.0;
     deg *= orientation;
 
-    return Some(deg);
+    Some(deg)
 }
 
 #[no_mangle]
 pub extern "C" fn fwk_exempi_manager_new() -> *mut ExempiManager {
-    return Box::into_raw(Box::new(ExempiManager::new(None)))
+    Box::into_raw(Box::new(ExempiManager::new(None)))
 }
 
 #[no_mangle]
-pub extern "C" fn fwk_exempi_manager_delete(em: *mut ExempiManager) {
-    unsafe { Box::from_raw(em); }
+pub unsafe extern "C" fn fwk_exempi_manager_delete(em: *mut ExempiManager) {
+    Box::from_raw(em);
 }
 
 #[cfg(test)]
diff --git a/src/libraryclient/clientimpl.rs b/src/libraryclient/clientimpl.rs
index 3e529e5..439acee 100644
--- a/src/libraryclient/clientimpl.rs
+++ b/src/libraryclient/clientimpl.rs
@@ -52,8 +52,8 @@ impl ClientImpl {
         let terminate2 = terminate.clone();
 
         /* let thread = */ thread::spawn(move || {
-            let library = Library::new(dir, None, notif_id);
-            Self::main(&mut terminate, tasks, &library);
+            let library = Library::new(&dir, None, notif_id);
+            Self::main(&mut terminate, &tasks, &library);
         });
 
 
@@ -69,7 +69,7 @@ impl ClientImpl {
     }
 
     fn main(terminate: &mut sync::Arc<atomic::AtomicBool>,
-            tasks: sync::Arc<(sync::Mutex<VecDeque<Op>>, sync::Condvar)>,
+            tasks: &sync::Arc<(sync::Mutex<VecDeque<Op>>, sync::Condvar)>,
             library: &Library) {
 
         while !terminate.load(atomic::Ordering::Relaxed) {
diff --git a/src/libraryclient/libraryclient.rs b/src/libraryclient/libraryclient.rs
index e752732..f56f3e9 100644
--- a/src/libraryclient/libraryclient.rs
+++ b/src/libraryclient/libraryclient.rs
@@ -164,14 +164,14 @@ impl ClientInterfaceSync for LibraryClient {
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_new(path: *const c_char, notif_id: u64) -> *mut LibraryClientWrapper {
-    let dir = PathBuf::from(&*unsafe { CStr::from_ptr(path) }.to_string_lossy());
+pub unsafe extern "C" fn libraryclient_new(path: *const c_char, notif_id: u64) -> *mut LibraryClientWrapper {
+    let dir = PathBuf::from(&*CStr::from_ptr(path).to_string_lossy());
     Box::into_raw(Box::new(LibraryClientWrapper::new(dir, notif_id)))
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_delete(obj: *mut LibraryClientWrapper) {
-    unsafe { Box::from_raw(obj); }
+pub unsafe extern "C" fn libraryclient_delete(obj: *mut LibraryClientWrapper) {
+    Box::from_raw(obj);
 }
 
 #[no_mangle]
@@ -201,14 +201,14 @@ pub extern "C" fn libraryclient_query_folder_content(client: &mut LibraryClientW
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_create_folder_sync(client: &mut LibraryClientWrapper,
-                                                   n: *const c_char,
-                                                   p: *const c_char) -> LibraryId {
-    let name = String::from(unsafe { CStr::from_ptr(n) }.to_string_lossy());
+pub unsafe extern "C" fn libraryclient_create_folder_sync(client: &mut LibraryClientWrapper,
+                                                          n: *const c_char,
+                                                          p: *const c_char) -> LibraryId {
+    let name = String::from(CStr::from_ptr(n).to_string_lossy());
     let path = if p.is_null() {
         None
     } else {
-        Some(String::from(unsafe { CStr::from_ptr(p) }.to_string_lossy()))
+        Some(String::from(CStr::from_ptr(p).to_string_lossy()))
     };
     client.unwrap_mut().create_folder_sync(name, path)
 }
@@ -270,18 +270,18 @@ pub extern "C" fn libraryclient_get_all_labels(client: &mut LibraryClientWrapper
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_create_label(client: &mut LibraryClientWrapper,
-                                             s: *const c_char, c: *const c_char) {
-    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
-    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
+pub unsafe extern "C" fn libraryclient_create_label(client: &mut LibraryClientWrapper,
+                                                    s: *const c_char, c: *const c_char) {
+    let name = CStr::from_ptr(s).to_string_lossy();
+    let colour = CStr::from_ptr(c).to_string_lossy();
     client.unwrap_mut().create_label(String::from(name), String::from(colour));
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_create_label_sync(
+pub unsafe extern "C" fn libraryclient_create_label_sync(
     client: &mut LibraryClientWrapper, s: *const c_char, c: *const c_char) -> LibraryId {
-    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
-    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
+    let name = CStr::from_ptr(s).to_string_lossy();
+    let colour = CStr::from_ptr(c).to_string_lossy();
     client.unwrap_mut().create_label_sync(String::from(name), String::from(colour))
 }
 
@@ -292,11 +292,11 @@ pub extern "C" fn libraryclient_delete_label(client: &mut LibraryClientWrapper,
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_update_label(client: &mut LibraryClientWrapper,
-                                             label_id: LibraryId,
-                                             s: *const c_char, c: *const c_char) {
-    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
-    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
+pub unsafe extern "C" fn libraryclient_update_label(client: &mut LibraryClientWrapper,
+                                                    label_id: LibraryId,
+                                                    s: *const c_char, c: *const c_char) {
+    let name = CStr::from_ptr(s).to_string_lossy();
+    let colour = CStr::from_ptr(c).to_string_lossy();
     client.unwrap_mut().update_label(label_id, String::from(name), String::from(colour));
 }
 
@@ -307,16 +307,16 @@ pub extern "C" fn libraryclient_process_xmp_update_queue(client: &mut LibraryCli
 }
 
 #[no_mangle]
-pub extern "C" fn libraryclient_import_files(client: &mut LibraryClientWrapper,
-                                             dir: *const c_char, cfiles: &mut FileList,
-                                             manage: Managed) {
-    let folder = unsafe { CStr::from_ptr(dir) }.to_string_lossy();
+pub unsafe extern "C" fn libraryclient_import_files(client: &mut LibraryClientWrapper,
+                                                    dir: *const c_char, cfiles: &mut FileList,
+                                                    manage: Managed) {
+    let folder = CStr::from_ptr(dir).to_string_lossy();
     let mut files: Vec<String> = vec!();
     {
-        let len = unsafe { cfiles.size() };
+        let len = cfiles.size();
         for i in 0..len {
-            let f = unsafe { cfiles.at_cstr(i) };
-            let cstr = unsafe { CStr::from_ptr(f) }.to_string_lossy();
+            let f = cfiles.at_cstr(i);
+            let cstr = CStr::from_ptr(f).to_string_lossy();
             files.push(String::from(cstr));
         }
     }
diff --git a/src/niepce/ui/dialogs/confirm.rs b/src/niepce/ui/dialogs/confirm.rs
index 3f275ed..ce3c825 100644
--- a/src/niepce/ui/dialogs/confirm.rs
+++ b/src/niepce/ui/dialogs/confirm.rs
@@ -29,12 +29,12 @@ use gtk::{
 };
 
 #[no_mangle]
-pub extern "C" fn dialog_confirm(message: *const c_char,
-                                 parent: *mut gtk_sys::GtkWindow) -> bool {
+pub unsafe extern "C" fn dialog_confirm(message: *const c_char,
+                                        parent: *mut gtk_sys::GtkWindow) -> bool {
 
     let mut result: bool = false;
-    let msg = unsafe { CStr::from_ptr(message) }.to_string_lossy();
-    let parent = unsafe { gtk::Window::from_glib_none(parent) };
+    let msg = CStr::from_ptr(message).to_string_lossy();
+    let parent = gtk::Window::from_glib_none(parent);
     let dialog = MessageDialog::new(Some(&parent), gtk::DialogFlags::MODAL,
                                     gtk::MessageType::Question, gtk::ButtonsType::YesNo,
                                     &*msg);
@@ -45,4 +45,4 @@ pub extern "C" fn dialog_confirm(message: *const c_char,
     dialog.destroy();
 
     result
-}
\ No newline at end of file
+}
diff --git a/src/niepce/ui/dialogs/requestnewfolder.rs b/src/niepce/ui/dialogs/requestnewfolder.rs
index 0274cad..2aa4e81 100644
--- a/src/niepce/ui/dialogs/requestnewfolder.rs
+++ b/src/niepce/ui/dialogs/requestnewfolder.rs
@@ -31,9 +31,9 @@ use gtk::{
 use libraryclient::{ClientInterface,LibraryClientWrapper};
 
 #[no_mangle]
-pub extern "C" fn dialog_request_new_folder(client: &mut LibraryClientWrapper,
-                                            parent: *mut gtk_sys::GtkWindow) {
-    let parent = unsafe { gtk::Window::from_glib_none(parent) };
+pub unsafe extern "C" fn dialog_request_new_folder(client: &mut LibraryClientWrapper,
+                                                   parent: *mut gtk_sys::GtkWindow) {
+    let parent = gtk::Window::from_glib_none(parent);
     let dialog = Dialog::new_with_buttons(
         Some("New folder"), Some(&parent),
         gtk::DialogFlags::MODAL,


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