1#[macro_export]
5macro_rules! optify {
6 ( $e: expr ) => {
7 match $e {
8 Ok(v) => Some(v),
9 Err(e) => {
10 tracing::error!("{}", e);
11 None
12 }
13 }
14 };
15 ( $e: expr, $msg: tt ) => {
16 match $e {
17 Ok(v) => Some(v),
18 Err(e) => {
19 tracing::error!("{}: {:?}", $msg, e);
20 None
21 }
22 }
23 };
24}
25
26#[macro_export]
27macro_rules! wasm_or_native {
28 (wasm => $wasm_block:block $(,)? native => $native_block:block $(,)?) => {
29 #[cfg(all(target_family = "wasm", target_os = "unknown"))]
30 $wasm_block
31 #[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
32 $native_block
33 };
34 (native => $native_block:block $(,)? wasm => $wasm_block:block $(,)?) => {
35 $crate::wasm_or_native!(wasm => $wasm_block, native => $native_block)
36 };
37}
38
39#[macro_export]
48macro_rules! wasm_or_native_expr {
49 (wasm => $wasm_expr:expr, native => $native_expr:expr $(,)?) => {
50 if cfg!(all(target_family = "wasm", target_os = "unknown")) {
51 $wasm_expr
52 } else {
53 $native_expr
54 }
55 };
56 (native => $native_expr:expr, wasm => $wasm_expr:expr $(,)?) => {
57 $crate::wasm_or_native_expr!(wasm => $wasm_expr, native => $native_expr)
58 };
59}
60
61#[macro_export]
63macro_rules! if_wasm {
64 (@ $($tt:tt)*) => {
66 #[cfg(all(target_family = "wasm", target_os = "unknown"))] {
67 $($tt)*
68 }
69 };
70 ($($item:item)*) => {$(
71 #[cfg(all(target_family = "wasm", target_os = "unknown"))]
72 $item
73 )*};
74}
75
76#[macro_export]
78macro_rules! if_native {
79 (@ $($tt:tt)*) => {
81 #[cfg(not(all(target_family = "wasm", target_os = "unknown")))] {
82 $($tt)*
83 }
84 };
85 ($($item:item)*) => {$(
86 #[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
87 $item
88 )*};
89}
90
91#[macro_export]
93macro_rules! if_d14n {
94 ($($item:item)*) => {$(
95 #[cfg(feature = "d14n")]
96 $item
97 )*}
98}
99
100#[macro_export]
102macro_rules! if_v3 {
103 ($($item:item)*) => {$(
104 #[cfg(not(feature = "d14n"))]
105 $item
106 )*}
107}
108
109#[macro_export]
111macro_rules! if_dev {
112 ($($item:item)*) => {$(
113 #[cfg(feature = "dev")]
114 $item
115 )*}
116}
117
118#[macro_export]
119macro_rules! if_local {
120 ($($item:item)*) => {$(
121 #[cfg(not(feature = "dev"))]
122 $item
123 )*}
124}
125
126#[macro_export]
127macro_rules! if_test {
128 ($($item:item)*) => {$(
129 #[cfg(any(test, feature = "test-utils"))]
130 $item
131 )*}
132}
133
134#[macro_export]
136macro_rules! if_only_test {
137 ($($item:item)*) => {$(
138 #[cfg(test)]
139 $item
140 )*}
141}
142
143#[macro_export]
144macro_rules! if_not_test {
145 ($($item:item)*) => {$(
146 #[cfg(not(any(test, feature = "test-utils")))]
147 $item
148 )*}
149}