open_timeline_gui/
macros.rs1#[macro_export]
12macro_rules! spawn_transaction_no_commit_send_result {
13 ($shared_config:ident, bounded, $tx:ident, $fetch_fn:expr) => {
14 tokio::spawn(async move {
15 let db_pool = $shared_config.read().await.db_pool.clone();
17
18 let result = async {
23 let mut transaction = db_pool.begin().await?;
24 $fetch_fn(&mut transaction).await
25 }
26 .await;
27 let _ = $tx.send(result).await;
28 });
29 };
30
31 ($shared_config:ident, unbounded, $tx:ident, $fetch_fn:expr) => {
32 tokio::spawn(async move {
33 let db_pool = $shared_config.read().await.db_pool.clone();
35
36 tokio::time::sleep(std::time::Duration::from_secs(0)).await;
38
39 let result = async {
40 let mut transaction = db_pool.begin().await?;
41 $fetch_fn(&mut transaction).await
42 }
43 .await;
44 let _ = $tx.send(result);
45 });
46 };
47}
48
49#[macro_export]
52macro_rules! impl_valid_asynchronous_macro_never_called {
53 ($type:ty) => {
54 impl open_timeline_gui_core::ValidAsynchronous for $type {
55 type Error = open_timeline_crud::CrudError;
56
57 fn is_valid_asynchronous(&self) -> Option<Result<(), Self::Error>> {
58 panic!()
60 }
61
62 fn check_for_asynchronous_validity_response(&mut self) {
63 panic!()
65 }
66
67 fn trigger_asynchronous_validity_update(&mut self) {
68 panic!()
70 }
71 }
72 };
73}
74
75#[macro_export]
78macro_rules! impl_valid_synchronous_macro_never_called {
79 ($type:ty) => {
80 impl open_timeline_gui_core::ValidSynchronous for $type {
81 fn is_valid_synchronous(&self) -> bool {
82 panic!()
84 }
85
86 fn update_validity_synchronous(&mut self) {
87 panic!()
89 }
90
91 fn validity_synchronous(&self) -> open_timeline_gui_core::ValiditySynchronous {
92 panic!()
94 }
95 }
96 };
97}
98
99#[macro_export]
102macro_rules! impl_is_valid_method_for_iterable {
103 ($iterable:expr) => {{
104 for validity in $iterable {
105 match validity {
106 open_timeline_gui_core::ValidityAsynchronous::Invalid(error) => {
107 return open_timeline_gui_core::ValidityAsynchronous::Invalid(error);
108 }
109 open_timeline_gui_core::ValidityAsynchronous::Waiting => {
110 return open_timeline_gui_core::ValidityAsynchronous::Waiting;
111 }
112 open_timeline_gui_core::ValidityAsynchronous::Valid => continue,
113 }
114 }
115 open_timeline_gui_core::ValidityAsynchronous::Valid
116 }};
117}