[niepce] rust: Address clippy warnings



commit 7589c91c9b646fb0e14cbfd595d86c424b42c989
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Feb 15 13:27:12 2020 -0500

    rust: Address clippy warnings
    
    - don't use once_cell::Lazy
    - remove lot of unsafe
    - add # Safety documentation as needed

 Cargo.lock                                         |  1 +
 crates/npc-engine/build.rs                         |  2 +-
 crates/npc-fwk/Cargo.toml                          |  1 +
 crates/npc-fwk/build.rs                            |  2 +-
 crates/npc-fwk/src/base/date.rs                    |  4 +
 crates/npc-fwk/src/base/mod.rs                     |  4 +
 crates/npc-fwk/src/base/propertybag.rs             | 62 +++++----------
 crates/npc-fwk/src/base/propertyvalue.rs           | 93 ++++++++++++----------
 crates/npc-fwk/src/base/rgbcolour.rs               |  4 +
 crates/npc-fwk/src/capi.rs                         |  3 +
 crates/npc-fwk/src/lib.rs                          | 10 +++
 crates/npc-fwk/src/toolkit/gdk_utils.rs            |  2 +-
 crates/npc-fwk/src/toolkit/mimetype.rs             |  3 +-
 crates/npc-fwk/src/toolkit/movieutils.rs           |  2 +-
 crates/npc-fwk/src/toolkit/thumbnail.rs            | 18 ++++-
 crates/npc-fwk/src/toolkit/widgets/rating_label.rs |  9 ++-
 crates/npc-fwk/src/utils/exempi.rs                 |  4 +
 crates/npc-fwk/src/utils/exiv2.rs                  |  9 +--
 crates/npc-fwk/src/utils/files.rs                  | 22 ++++-
 niepce-main/build.rs                               |  2 +-
 src/Makefile.am                                    |  2 +-
 21 files changed, 154 insertions(+), 105 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 6f35b0e..57c0dfc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -647,6 +647,7 @@ dependencies = [
  "glib-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gtk 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gtk-sys 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
  "multimap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "once_cell 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/crates/npc-engine/build.rs b/crates/npc-engine/build.rs
index e35b4cd..31186b3 100644
--- a/crates/npc-engine/build.rs
+++ b/crates/npc-engine/build.rs
@@ -59,7 +59,7 @@ fn main() {
     if env::var("SKIP_CBINDINGS").is_err() {
         // Use cbindgen to generate C bindings.
         let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
-        let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or(String::from("./target"));
+        let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| String::from("./target"));
         let mut target_file = PathBuf::from(target_dir);
         target_file.push("eng_bindings.h");
         cbindgen::Builder::new()
diff --git a/crates/npc-fwk/Cargo.toml b/crates/npc-fwk/Cargo.toml
index 601582c..6fc3d5a 100644
--- a/crates/npc-fwk/Cargo.toml
+++ b/crates/npc-fwk/Cargo.toml
@@ -20,6 +20,7 @@ gdk = "^0.12.0"
 gdk-pixbuf-sys = "*"
 gdk-pixbuf = { version = "0.8.0", features = [ "v2_32" ] }
 gtk = { version = "^0.8.1" }
+lazy_static = "^1.2.0"
 libc = "0.2.39"
 multimap = "0.4.0"
 once_cell = "^0"
diff --git a/crates/npc-fwk/build.rs b/crates/npc-fwk/build.rs
index cdbb50c..f41dafb 100644
--- a/crates/npc-fwk/build.rs
+++ b/crates/npc-fwk/build.rs
@@ -7,7 +7,7 @@ fn main() {
     if env::var("SKIP_CBINDINGS").is_err() {
         // Use cbindgen to generate C bindings.
         let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
-        let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or(String::from("./target"));
+        let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| String::from("./target"));
         let mut target_file = PathBuf::from(target_dir);
         target_file.push("fwk_bindings.h");
         cbindgen::Builder::new()
diff --git a/crates/npc-fwk/src/base/date.rs b/crates/npc-fwk/src/base/date.rs
index 4dfb64b..97680b9 100644
--- a/crates/npc-fwk/src/base/date.rs
+++ b/crates/npc-fwk/src/base/date.rs
@@ -36,6 +36,10 @@ pub fn xmp_date_from(d: &chrono::DateTime<chrono::Utc>) -> exempi::DateTime {
     xmp_date
 }
 
+/// Delete a %Date object
+///
+/// # Safety
+/// Dereference the raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_date_delete(date: *mut Date) {
     Box::from_raw(date);
diff --git a/crates/npc-fwk/src/base/mod.rs b/crates/npc-fwk/src/base/mod.rs
index e0a2f09..8c334c4 100644
--- a/crates/npc-fwk/src/base/mod.rs
+++ b/crates/npc-fwk/src/base/mod.rs
@@ -38,6 +38,10 @@ pub extern "C" fn fwk_property_set_new() -> *mut PropertySet {
     Box::into_raw(Box::new(PropertySet::new()))
 }
 
+/// Delete a %PropertySet
+///
+/// # Safety
+/// Dereference the pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_property_set_delete(set: *mut PropertySet) {
     Box::from_raw(set);
diff --git a/crates/npc-fwk/src/base/propertybag.rs b/crates/npc-fwk/src/base/propertybag.rs
index 153809a..967498a 100644
--- a/crates/npc-fwk/src/base/propertybag.rs
+++ b/crates/npc-fwk/src/base/propertybag.rs
@@ -57,68 +57,48 @@ pub extern "C" fn fwk_property_bag_new() -> *mut PropertyBag {
     Box::into_raw(Box::new(PropertyBag::new()))
 }
 
+/// Delete the %PropertyBag object
+///
+/// # Safety
+/// Dereference the raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_property_bag_delete(bag: *mut PropertyBag) {
     Box::from_raw(bag);
 }
 
 #[no_mangle]
-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,
-    }
+pub extern "C" fn fwk_property_bag_is_empty(b: &PropertyBag) -> bool {
+    b.is_empty()
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_len(b: *const PropertyBag) -> usize {
-    match b.as_ref() {
-        Some(ref pb) => pb.len(),
-        None => unreachable!(),
-    }
+pub extern "C" fn fwk_property_bag_len(b: &PropertyBag) -> usize {
+    b.len()
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_key_by_index(
-    b: *const PropertyBag,
-    idx: usize,
-) -> PropertyIndex {
-    match b.as_ref() {
-        Some(ref pb) => pb.bag[idx],
-        None => unreachable!(),
-    }
+pub extern "C" fn fwk_property_bag_key_by_index(b: &PropertyBag, idx: usize) -> PropertyIndex {
+    b.bag[idx]
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_value(
-    b: *const PropertyBag,
+pub extern "C" fn fwk_property_bag_value(
+    b: &PropertyBag,
     key: PropertyIndex,
 ) -> *mut PropertyValue {
-    match b.as_ref() {
-        Some(ref pb) => {
-            if pb.map.contains_key(&key) {
-                let value = Box::new(pb.map[&key].clone());
-                Box::into_raw(value)
-            } else {
-                ptr::null_mut()
-            }
-        }
-        None => unreachable!(),
+    if b.map.contains_key(&key) {
+        let value = Box::new(b.map[&key].clone());
+        Box::into_raw(value)
+    } else {
+        ptr::null_mut()
     }
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_set_value(
-    b: *mut PropertyBag,
+pub extern "C" fn fwk_property_bag_set_value(
+    b: &mut PropertyBag,
     key: PropertyIndex,
-    v: *const PropertyValue,
+    v: &PropertyValue,
 ) -> bool {
-    let value = match v.as_ref() {
-        Some(value) => value.clone(),
-        None => unreachable!(),
-    };
-    match b.as_mut() {
-        Some(ref mut pb) => pb.set_value(key, value),
-        None => unreachable!(),
-    }
+    b.set_value(key, v.clone())
 }
diff --git a/crates/npc-fwk/src/base/propertyvalue.rs b/crates/npc-fwk/src/base/propertyvalue.rs
index c6fb754..9e96ccf 100644
--- a/crates/npc-fwk/src/base/propertyvalue.rs
+++ b/crates/npc-fwk/src/base/propertyvalue.rs
@@ -33,6 +33,10 @@ pub enum PropertyValue {
 
 unsafe impl Send for PropertyValue {}
 
+/// Create a new String %PropertyValue from a C string
+///
+/// # Safety
+/// Dereference the pointer (C string)
 #[no_mangle]
 pub unsafe extern "C" fn fwk_property_value_new_str(v: *const c_char) -> *mut PropertyValue {
     let cstr = CStr::from_ptr(v);
@@ -58,6 +62,10 @@ pub extern "C" fn fwk_property_value_new_string_array() -> *mut PropertyValue {
     Box::into_raw(value)
 }
 
+/// Delete the %PropertyValue object
+///
+/// # Safety
+/// Dereference the pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_property_value_delete(v: *mut PropertyValue) {
     if !v.is_null() {
@@ -66,88 +74,89 @@ pub unsafe extern "C" fn fwk_property_value_delete(v: *mut PropertyValue) {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_is_empty(v: *const PropertyValue) -> bool {
-    match v.as_ref() {
-        Some(&PropertyValue::Empty) => true,
+pub extern "C" fn fwk_property_value_is_empty(v: &PropertyValue) -> bool {
+    match *v {
+        PropertyValue::Empty => true,
         _ => false,
     }
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_is_integer(v: *const PropertyValue) -> bool {
-    match v.as_ref() {
-        Some(&PropertyValue::Int(_)) => true,
+pub extern "C" fn fwk_property_value_is_integer(v: &PropertyValue) -> bool {
+    match *v {
+        PropertyValue::Int(_) => true,
         _ => false,
     }
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_get_integer(v: *const PropertyValue) -> i32 {
-    match v.as_ref() {
-        Some(&PropertyValue::Int(i)) => i,
-        _ => unreachable!(),
+pub extern "C" fn fwk_property_value_get_integer(v: &PropertyValue) -> i32 {
+    match *v {
+        PropertyValue::Int(i) => i,
+        _ => panic!("value is not Int"),
     }
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_is_date(v: *const PropertyValue) -> bool {
-    match v.as_ref() {
-        Some(&PropertyValue::Date(_)) => true,
+pub extern "C" fn fwk_property_value_is_date(v: &PropertyValue) -> bool {
+    match *v {
+        PropertyValue::Date(_) => true,
         _ => false,
     }
 }
 
 #[no_mangle]
-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!(),
+pub extern "C" fn fwk_property_value_get_date(v: &PropertyValue) -> *const Date {
+    match *v {
+        PropertyValue::Date(ref d) => d,
+        _ => panic!("value is not Date"),
     }
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_is_string(v: *const PropertyValue) -> bool {
-    match v.as_ref() {
-        Some(&PropertyValue::String(_)) => true,
+pub extern "C" fn fwk_property_value_is_string(v: &PropertyValue) -> bool {
+    match *v {
+        PropertyValue::String(_) => true,
         _ => false,
     }
 }
 
 #[no_mangle]
-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(),
-        _ => unreachable!(),
+pub extern "C" fn fwk_property_value_get_string(v: &PropertyValue) -> *mut c_char {
+    match *v {
+        PropertyValue::String(ref s) => CString::new(s.as_bytes()).unwrap().into_raw(),
+        _ => panic!("value is not a String"),
     }
 }
 
+/// Add a string a StringArray %PropertyValue
+///
+/// Will panic if the type is incorrect.
+///
+/// # Safety
+/// Dereference the pointer (C string)
 #[no_mangle]
-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(CStr::from_ptr(str).to_string_lossy().into_owned());
+pub unsafe extern "C" fn fwk_property_value_add_string(v: &mut PropertyValue, cstr: *const c_char) {
+    match *v {
+        PropertyValue::StringArray(ref mut sa) => {
+            sa.push(CStr::from_ptr(cstr).to_string_lossy().into_owned());
         }
-        _ => unreachable!(),
+        _ => panic!("value is not a StringArray"),
     }
 }
 
 #[no_mangle]
-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(),
-        _ => unreachable!(),
+pub extern "C" fn fwk_property_value_count_string_array(v: &PropertyValue) -> usize {
+    match *v {
+        PropertyValue::StringArray(ref sa) => sa.len(),
+        _ => panic!("value is not a StringArray"),
     }
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_get_string_at(
-    v: *const PropertyValue,
-    idx: usize,
-) -> *mut c_char {
-    match v.as_ref() {
-        Some(&PropertyValue::StringArray(ref sa)) => {
-            CString::new(sa[idx].as_bytes()).unwrap().into_raw()
-        }
-        _ => unreachable!(),
+pub extern "C" fn fwk_property_value_get_string_at(v: &PropertyValue, idx: usize) -> *mut c_char {
+    match *v {
+        PropertyValue::StringArray(ref sa) => CString::new(sa[idx].as_bytes()).unwrap().into_raw(),
+        _ => panic!("value is not a StringArray"),
     }
 }
diff --git a/crates/npc-fwk/src/base/rgbcolour.rs b/crates/npc-fwk/src/base/rgbcolour.rs
index 4745a57..d4148ef 100644
--- a/crates/npc-fwk/src/base/rgbcolour.rs
+++ b/crates/npc-fwk/src/base/rgbcolour.rs
@@ -92,6 +92,10 @@ pub extern "C" fn fwk_rgbcolour_to_string(c: &RgbColour) -> *mut c_char {
     CString::new(c.to_string().as_bytes()).unwrap().into_raw()
 }
 
+/// Delete the %RgbColour object
+///
+/// # Safety
+/// Dereference the pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_rgbcolour_delete(c: *mut RgbColour) {
     Box::from_raw(c);
diff --git a/crates/npc-fwk/src/capi.rs b/crates/npc-fwk/src/capi.rs
index a0f5c90..207f684 100644
--- a/crates/npc-fwk/src/capi.rs
+++ b/crates/npc-fwk/src/capi.rs
@@ -21,6 +21,9 @@ use libc::c_char;
 use std::ffi::CString;
 
 /// Release the raw pointer from a CString.
+///
+/// # Safety
+/// Dereference the pointer
 #[no_mangle]
 pub unsafe extern "C" fn rust_cstring_delete(string: *mut c_char) {
     CString::from_raw(string);
diff --git a/crates/npc-fwk/src/lib.rs b/crates/npc-fwk/src/lib.rs
index 8ddd2af..4147819 100644
--- a/crates/npc-fwk/src/lib.rs
+++ b/crates/npc-fwk/src/lib.rs
@@ -29,6 +29,8 @@ extern crate glib;
 extern crate glib_sys;
 extern crate gtk;
 extern crate gtk_sys;
+#[macro_use]
+extern crate lazy_static;
 extern crate libc;
 extern crate multimap;
 extern crate once_cell;
@@ -55,6 +57,10 @@ use libc::c_char;
 use std::f64;
 use std::ffi::CStr;
 
+/// Convert a gps coord (in string format) to a decimal (floating point)
+///
+/// # Safety
+/// Dereference the pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
     let value = CStr::from_ptr(cvalue);
@@ -66,6 +72,10 @@ pub unsafe extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
     f64::NAN
 }
 
+/// Convert a fraction (in string format) to a decimal (floating point)
+///
+/// # Safety
+/// Dereference the pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_fraction_to_decimal(cvalue: *const c_char) -> f64 {
     let value = CStr::from_ptr(cvalue);
diff --git a/crates/npc-fwk/src/toolkit/gdk_utils.rs b/crates/npc-fwk/src/toolkit/gdk_utils.rs
index 6f1bbd4..dd4e52a 100644
--- a/crates/npc-fwk/src/toolkit/gdk_utils.rs
+++ b/crates/npc-fwk/src/toolkit/gdk_utils.rs
@@ -54,7 +54,7 @@ pub fn gdkpixbuf_exif_rotate(
     orientation: i32,
 ) -> Option<gdk_pixbuf::Pixbuf> {
     match orientation {
-        0 | 1 => pix.map(|p| p.clone()),
+        0 | 1 => pix.cloned(),
         2 => pix.and_then(|p| p.flip(true)),
         3 => pix.and_then(|p| p.rotate_simple(gdk_pixbuf::PixbufRotation::Upsidedown)),
         4 => pix
diff --git a/crates/npc-fwk/src/toolkit/mimetype.rs b/crates/npc-fwk/src/toolkit/mimetype.rs
index c03b187..fe8a9dd 100644
--- a/crates/npc-fwk/src/toolkit/mimetype.rs
+++ b/crates/npc-fwk/src/toolkit/mimetype.rs
@@ -77,9 +77,8 @@ fn guess_type_for_file<P: AsRef<Path>>(p: P) -> MType {
     }
     // alternative
     let (content_type, _) = gio::content_type_guess(path.to_str(), &[]);
-    let t = guess_type(content_type.as_str());
 
-    t
+    guess_type(content_type.as_str())
 }
 
 impl MimeType {
diff --git a/crates/npc-fwk/src/toolkit/movieutils.rs b/crates/npc-fwk/src/toolkit/movieutils.rs
index 42a0e8d..385f5b4 100644
--- a/crates/npc-fwk/src/toolkit/movieutils.rs
+++ b/crates/npc-fwk/src/toolkit/movieutils.rs
@@ -32,6 +32,6 @@ where
         .arg(source.as_ref().as_os_str())
         .arg(dest.as_ref().as_os_str())
         .status()
-        .expect(&format!("Failed to thumbnail {:?}", source));
+        .unwrap_or_else(|_| panic!("Failed to thumbnail {:?}", source));
     status.success()
 }
diff --git a/crates/npc-fwk/src/toolkit/thumbnail.rs b/crates/npc-fwk/src/toolkit/thumbnail.rs
index 91306cc..25a35d2 100644
--- a/crates/npc-fwk/src/toolkit/thumbnail.rs
+++ b/crates/npc-fwk/src/toolkit/thumbnail.rs
@@ -61,7 +61,7 @@ impl Default for Thumbnail {
 impl Thumbnail {
     /// Return true if there is a pixbuf
     pub fn ok(&self) -> bool {
-        self.bytes.len() > 0
+        !self.bytes.is_empty()
     }
 
     /// Get the width of the pixbuf. 0 if None
@@ -191,6 +191,10 @@ impl Into<gdk_pixbuf::Pixbuf> for Thumbnail {
     }
 }
 
+/// Generate the %Thumbnail for the file
+///
+/// # Safety
+/// Dereference filename pointer (C string)
 #[no_mangle]
 pub unsafe extern "C" fn fwk_toolkit_thumbnail_file(
     filename: *const c_char,
@@ -206,11 +210,21 @@ pub unsafe extern "C" fn fwk_toolkit_thumbnail_file(
     )))
 }
 
+/// Delete the %Thumbnail object
+///
+/// # Safety
+/// Dereference the pointer
 #[no_mangle]
 pub unsafe extern "C" fn fwk_toolkit_thumbnail_delete(obj: *mut Thumbnail) {
     Box::from_raw(obj);
 }
 
+/// Create a %Thumbnail from a %GdkPixbuf
+///
+/// The resulting object must be freed by %fwk_toolkit_thumbnail_delete
+///
+/// # Safety
+/// Dereference the pointer
 #[no_mangle]
 pub unsafe extern "C" fn fwk_toolkit_thumbnail_from_pixbuf(
     pixbuf: *mut gdk_pixbuf_sys::GdkPixbuf,
@@ -220,7 +234,7 @@ pub unsafe extern "C" fn fwk_toolkit_thumbnail_from_pixbuf(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_toolkit_thumbnail_to_pixbuf(
+pub extern "C" fn fwk_toolkit_thumbnail_to_pixbuf(
     self_: &Thumbnail,
 ) -> *mut gdk_pixbuf_sys::GdkPixbuf {
     self_.make_pixbuf().to_glib_full()
diff --git a/crates/npc-fwk/src/toolkit/widgets/rating_label.rs 
b/crates/npc-fwk/src/toolkit/widgets/rating_label.rs
index d50d67b..318e108 100644
--- a/crates/npc-fwk/src/toolkit/widgets/rating_label.rs
+++ b/crates/npc-fwk/src/toolkit/widgets/rating_label.rs
@@ -269,15 +269,16 @@ impl WidgetImpl for RatingLabelPriv {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_rating_label_new(
-    rating: c_int,
-    editable: bool,
-) -> *mut gtk_sys::GtkWidget {
+pub extern "C" fn fwk_rating_label_new(rating: c_int, editable: bool) -> *mut gtk_sys::GtkWidget {
     RatingLabel::new(rating, editable)
         .upcast::<gtk::Widget>()
         .to_glib_full()
 }
 
+/// Set the rating for the %RatingLabel widget
+///
+/// # Safety
+/// Dereference the widget pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_rating_label_set_rating(
     widget: *mut gtk_sys::GtkDrawingArea,
diff --git a/crates/npc-fwk/src/utils/exempi.rs b/crates/npc-fwk/src/utils/exempi.rs
index f23dd6f..4d27623 100644
--- a/crates/npc-fwk/src/utils/exempi.rs
+++ b/crates/npc-fwk/src/utils/exempi.rs
@@ -515,6 +515,10 @@ pub extern "C" fn fwk_exempi_manager_new() -> *mut ExempiManager {
     Box::into_raw(Box::new(ExempiManager::new(None)))
 }
 
+/// Delete the ExempiManager
+///
+/// # Safety
+/// Dereference the pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_exempi_manager_delete(em: *mut ExempiManager) {
     Box::from_raw(em);
diff --git a/crates/npc-fwk/src/utils/exiv2.rs b/crates/npc-fwk/src/utils/exiv2.rs
index 7b698b3..7b2aed3 100644
--- a/crates/npc-fwk/src/utils/exiv2.rs
+++ b/crates/npc-fwk/src/utils/exiv2.rs
@@ -20,8 +20,6 @@
 use multimap::MultiMap;
 use std::ffi::OsStr;
 
-use once_cell::unsync::Lazy;
-
 use exempi;
 use rexiv2;
 
@@ -55,8 +53,8 @@ enum Converted {
     Flash(Flash),
 }
 
-const EXIV2_TO_XMP: Lazy<MultiMap<&'static str, (&'static str, &'static str, Conversion)>> =
-    Lazy::new(|| {
+lazy_static! {
+    static ref EXIV2_TO_XMP: MultiMap<&'static str, (&'static str, &'static str, Conversion)> = {
         [
             (
                 "Exif.Image.DateTime",
@@ -232,7 +230,8 @@ const EXIV2_TO_XMP: Lazy<MultiMap<&'static str, (&'static str, &'static str, Con
         .iter()
         .cloned()
         .collect()
-    });
+    };
+}
 
 fn convert(conversion: Conversion, value: &str) -> Converted {
     match conversion {
diff --git a/crates/npc-fwk/src/utils/files.rs b/crates/npc-fwk/src/utils/files.rs
index 1f053be..80c94de 100644
--- a/crates/npc-fwk/src/utils/files.rs
+++ b/crates/npc-fwk/src/utils/files.rs
@@ -89,6 +89,10 @@ impl FileList {
     }
 }
 
+/// Tell is the file pointed by finfo is a media file
+///
+/// # Safety
+/// Dereference the finfo pointer.
 #[no_mangle]
 pub unsafe extern "C" fn fwk_file_is_media(finfo: *mut gio_sys::GFileInfo) -> bool {
     let fileinfo = gio::FileInfo::from_glib_none(finfo);
@@ -96,15 +100,23 @@ pub unsafe extern "C" fn fwk_file_is_media(finfo: *mut gio_sys::GFileInfo) -> bo
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_file_list_new() -> *mut FileList {
+pub extern "C" fn fwk_file_list_new() -> *mut FileList {
     Box::into_raw(Box::new(FileList::default()))
 }
 
+/// Delete the file list object from ffi code
+///
+/// # Safety
+/// Dereference the pointer
 #[no_mangle]
 pub unsafe extern "C" fn fwk_file_list_delete(l: *mut FileList) {
     Box::from_raw(l);
 }
 
+/// Get the files in directory dir
+///
+/// # Safety
+/// Dereference the dir pointer (C String)
 #[no_mangle]
 pub unsafe extern "C" fn fwk_file_list_get_files_from_directory(
     dir: *const c_char,
@@ -127,20 +139,24 @@ pub unsafe extern "C" fn fwk_file_list_get_files_from_directory(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fwk_file_list_size(l: &FileList) -> usize {
+pub extern "C" fn fwk_file_list_size(l: &FileList) -> usize {
     l.0.len()
 }
 
 /// Return the path string at index %idx
 /// The resulting string must be freeed with %rust_cstring_delete
 #[no_mangle]
-pub unsafe extern "C" fn fwk_file_list_at(l: &FileList, idx: usize) -> *mut c_char {
+pub extern "C" fn fwk_file_list_at(l: &FileList, idx: usize) -> *mut c_char {
     CString::new(l.0[idx].to_string_lossy().as_bytes())
         .unwrap()
         .into_raw()
 }
 
 #[no_mangle]
+/// Push a file path to the list
+///
+/// # Safety
+/// Dereference the value pointer (C string)
 pub unsafe extern "C" fn fwk_file_list_push_back(l: &mut FileList, value: *const c_char) {
     assert!(!value.is_null());
     if value.is_null() {
diff --git a/niepce-main/build.rs b/niepce-main/build.rs
index 5877a7b..7c041a0 100644
--- a/niepce-main/build.rs
+++ b/niepce-main/build.rs
@@ -7,7 +7,7 @@ fn main() {
     let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
     if env::var("SKIP_CBINDINGS").is_err() {
         // Use cbindgen to generate C bindings.
-        let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or(String::from("./target"));
+        let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| String::from("./target"));
         let mut target_file = PathBuf::from(target_dir);
         target_file.push("bindings.h");
         cbindgen::Builder::new()
diff --git a/src/Makefile.am b/src/Makefile.am
index 06b0ee1..0bb02c0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -101,4 +101,4 @@ check-local:
 
 clippy:
        cd $(top_srcdir) && \
-       CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) cargo clippy $(CARGO_VERBOSE) $(CARGO_RELEASE_ARGS) -- -A 
clippy::missing_safety_doc
+       CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) cargo clippy $(CARGO_VERBOSE) $(CARGO_RELEASE_ARGS)


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