From b8010be26b4e2d489f55ba01622f9b6e1685b3b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Garc=C3=ADa?=
 <dani-garcia@users.noreply.github.com>
Date: Sun, 2 May 2021 17:49:25 +0200
Subject: [PATCH] Extract some FromDb trait impls outside the macros so they
 aren't repeated, and fix some clippy lints

---
 src/api/icons.rs |  2 +-
 src/db/mod.rs    | 29 +++++++++++++++++++----------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/api/icons.rs b/src/api/icons.rs
index 33849bbb..b7674f3a 100644
--- a/src/api/icons.rs
+++ b/src/api/icons.rs
@@ -354,8 +354,8 @@ struct Icon {
 impl Icon {
     const fn new(priority: u8, href: String) -> Self {
         Self {
-            href,
             priority,
+            href,
         }
     }
 }
diff --git a/src/db/mod.rs b/src/db/mod.rs
index ba922427..eca0c956 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -157,6 +157,24 @@ pub trait FromDb {
     fn from_db(self) -> Self::Output;
 }
 
+impl<T: FromDb> FromDb for Vec<T> {
+    type Output = Vec<T::Output>;
+    #[allow(clippy::wrong_self_convention)]
+    #[inline(always)]
+    fn from_db(self) -> Self::Output {
+        self.into_iter().map(crate::db::FromDb::from_db).collect()
+    }
+}
+
+impl<T: FromDb> FromDb for Option<T> {
+    type Output = Option<T::Output>;
+    #[allow(clippy::wrong_self_convention)]
+    #[inline(always)]
+    fn from_db(self) -> Self::Output {
+        self.map(crate::db::FromDb::from_db)
+    }
+}
+
 // For each struct eg. Cipher, we create a CipherDb inside a module named __$db_model (where $db is sqlite, mysql or postgresql),
 // to implement the Diesel traits. We also provide methods to convert between them and the basic structs. Later, that module will be auto imported when using db_run!
 #[macro_export]
@@ -197,18 +215,9 @@ macro_rules! db_object {
 
             impl crate::db::FromDb for [<$name Db>] {
                 type Output = super::$name;
+                #[allow(clippy::wrong_self_convention)]
                 #[inline(always)] fn from_db(self) -> Self::Output { super::$name { $( $field: self.$field, )+ } }
             }
-
-            impl crate::db::FromDb for Vec<[<$name Db>]> {
-                type Output = Vec<super::$name>;
-                #[inline(always)] fn from_db(self) -> Self::Output { self.into_iter().map(crate::db::FromDb::from_db).collect() }
-            }
-
-            impl crate::db::FromDb for Option<[<$name Db>]> {
-                type Output = Option<super::$name>;
-                #[inline(always)] fn from_db(self) -> Self::Output { self.map(crate::db::FromDb::from_db) }
-            }
         }
     };
 }