macros_rs/
obj.rs

1#[doc(hidden)]
2#[macro_export]
3macro_rules! _lib_scaffold {
4  (pub struct $name:ident { $($field:ident: $type:ty),* $(,)? }) => {
5    impl $name {
6        #[allow(dead_code, unused)]
7        fn write(self, buf: &mut [u32]) {
8        let mut offset = 0;
9        $(
10            let value = self.$field as u64;
11            buf[offset] = value as u32;
12            buf[offset + 1] = (value >> 32) as u32;
13            #[allow(unused_assignments)]
14            {
15                offset += 2;
16            }
17        )*
18      }
19    }
20
21    #[derive(Serialize)]
22    #[serde(rename_all = "camelCase")]
23    struct $name {
24        $($field: $type),*
25    }
26  };
27}
28
29#[doc(hidden)]
30#[macro_export]
31macro_rules! _lib_derive {
32  (pub struct $name:ident { $($field:ident: $type:ty),* $(,)? }) => {
33    #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
34    struct $name {
35        $($field: $type),*
36    }
37  };
38}
39
40#[doc(hidden)]
41#[macro_export]
42macro_rules! _lib_clone {
43    ($obj:expr) => {
44        $obj.clone()
45    };
46}
47
48#[doc(hidden)]
49#[macro_export]
50macro_rules! _lib_lazy_lock {
51    ($(#[$attr:meta])* static $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
52        $crate::__lazy_lock_internal!($(#[$attr])* () static $N : $T = $e; $($t)*);
53    };
54    ($(#[$attr:meta])* pub static $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
55        $crate::__lazy_lock_internal!($(#[$attr])* (pub) static $N : $T = $e; $($t)*);
56    };
57    ($(#[$attr:meta])* pub ($($vis:tt)+) static $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
58        $crate::__lazy_lock_internal!($(#[$attr])* (pub ($($vis)+)) static $N : $T = $e; $($t)*);
59    };
60    () => ()
61}
62
63#[doc(hidden)]
64#[macro_export]
65macro_rules! __lazy_lock_internal {
66    ($(#[$attr:meta])* ($($vis:tt)*) static $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
67        $(#[$attr])*
68        $($vis)* static $N: std::sync::LazyLock<$T> = std::sync::LazyLock::new(|| $e);
69        $crate::obj::lazy_lock!($($t)*);
70    };
71    () => ()
72}
73
74#[doc(inline)]
75pub use _lib_scaffold as scaffold;
76
77#[doc(inline)]
78pub use _lib_derive as derive;
79
80#[doc(inline)]
81pub use _lib_clone as clone;
82
83#[doc(inline)]
84pub use _lib_lazy_lock as lazy_lock;