sqlx_utils/macros/db/
repo_static.rs

1#[macro_export]
2macro_rules! static_repo {
3    /*(
4        $vis:vis $ident:ident;
5        $init_method:ident($($param:pat_param = $param_ty:ty),*) -> $return_ty:ty $init_block:block
6    ) => {
7        ::paste::paste! {
8            $vis static [<$ident:snake:upper>]: ::tokio::sync::OnceCell<$return_ty> = ::tokio::sync::OnceCell::const_new();
9
10            #[inline(always)]
11            #[tracing::instrument(level = "debug")]
12            fn $init_method($($param: $param_ty),*) -> $crate::error::Result<$return_ty> $init_block
13
14            #[inline(always)]
15            #[tracing::instrument(level = "debug")]
16            $vis fn [<get_ $ident:snake>]() -> $crate::error::Result<&'static $return_ty> {
17                [<$ident:snake:upper>].get_or_try_init($init_method).await
18            }
19        }
20    };
21
22    ($vis:vis $ident:ident;) => {
23        ::paste::paste! {
24            $crate::static_repo!(
25                $vis $ident;
26
27                [<init_ $ident:snake:lower>]() -> $ident {
28                    $ident::new().await
29                }
30            );
31        }
32    };*/
33
34    ($vis:vis $ident:ident;) => {
35        ::paste::paste! {
36            $vis static [<$ident:snake:upper>]: ::std::sync::LazyLock<$ident> = ::std::sync::LazyLock::new(|| {
37                $ident::new()
38            });
39        }
40    };
41
42    (!zst $vis:vis $ident:ident;) => {
43        ::paste::paste! {
44            $vis static [<$ident:snake:upper>]: $ident = $ident::new();
45        }
46    };
47}