mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-11-22 20:03:19 +00:00
Extract some FromDb trait impls outside the macros so they aren't repeated, and fix some clippy lints
This commit is contained in:
parent
f76b8a32ca
commit
b8010be26b
2 changed files with 20 additions and 11 deletions
|
@ -354,8 +354,8 @@ struct Icon {
|
||||||
impl Icon {
|
impl Icon {
|
||||||
const fn new(priority: u8, href: String) -> Self {
|
const fn new(priority: u8, href: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
href,
|
|
||||||
priority,
|
priority,
|
||||||
|
href,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,24 @@ pub trait FromDb {
|
||||||
fn from_db(self) -> Self::Output;
|
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),
|
// 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!
|
// 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]
|
#[macro_export]
|
||||||
|
@ -197,18 +215,9 @@ macro_rules! db_object {
|
||||||
|
|
||||||
impl crate::db::FromDb for [<$name Db>] {
|
impl crate::db::FromDb for [<$name Db>] {
|
||||||
type Output = super::$name;
|
type Output = super::$name;
|
||||||
|
#[allow(clippy::wrong_self_convention)]
|
||||||
#[inline(always)] fn from_db(self) -> Self::Output { super::$name { $( $field: self.$field, )+ } }
|
#[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) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue