2021-07-20 06:03:21 +00:00
|
|
|
// #[macro_export]
|
|
|
|
// macro_rules! impl_save_func {
|
|
|
|
// ($func_name:ident, $target:ident, $table_name:expr, $conn:ident) => {
|
2021-12-14 10:04:51 +00:00
|
|
|
// fn $func_name(object: $target) -> Result<(), FlowyError> {
|
2021-07-20 06:03:21 +00:00
|
|
|
// let _ = diesel::insert_into($table_name)
|
|
|
|
// .values($target)
|
|
|
|
// .execute(&*($conn))?;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! impl_def_and_def_mut {
|
|
|
|
($target:ident, $item: ident) => {
|
|
|
|
impl std::ops::Deref for $target {
|
|
|
|
type Target = Vec<$item>;
|
|
|
|
|
2022-01-23 04:14:00 +00:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.items
|
|
|
|
}
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
|
|
|
impl std::ops::DerefMut for $target {
|
2022-01-23 04:14:00 +00:00
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.items
|
|
|
|
}
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl $target {
|
|
|
|
#[allow(dead_code)]
|
2022-01-23 04:14:00 +00:00
|
|
|
pub fn into_inner(&mut self) -> Vec<$item> {
|
|
|
|
::std::mem::replace(&mut self.items, vec![])
|
|
|
|
}
|
2021-07-20 06:03:21 +00:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn push(&mut self, item: $item) {
|
|
|
|
if self.items.contains(&item) {
|
|
|
|
log::error!("add duplicate item: {:?}", item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.items.push(item);
|
|
|
|
}
|
|
|
|
|
2022-01-23 04:14:00 +00:00
|
|
|
pub fn first_or_crash(&self) -> &$item {
|
|
|
|
self.items.first().unwrap()
|
|
|
|
}
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|