irox_tools/
macros.rs

1// SPDX-License-Identifier: MIT
2// Copyright 2025 IROX Contributors
3//
4
5//!
6//! Macros for better documentation.
7
8/// Enables Windows-specific code.
9/// Use this macro instead of `cfg(windows)` to generate docs properly.
10#[macro_export]
11macro_rules! cfg_windows {
12    ($($item:item)*) => {
13        $(
14            #[cfg(any(all(doc, docsrs), windows))]
15            #[cfg_attr(docsrs, doc(cfg(windows)))]
16            $item
17        )*
18    }
19}
20
21/// Enables Unix-specific code.
22/// Use this macro instead of `cfg(unix)` to generate docs properly.
23#[macro_export]
24macro_rules! cfg_unix {
25    ($($item:item)*) => {
26        $(
27            #[cfg(any(all(doc, docsrs), unix))]
28            #[cfg_attr(docsrs, doc(cfg(unix)))]
29            $item
30        )*
31    }
32}
33
34///
35/// Use for things that are only valid for documentation generation
36#[macro_export]
37macro_rules! cfg_docs {
38    ($($item:item)*) => {
39        $(
40            #[cfg(all(doc, docsrs))]
41            $item
42        )*
43    };
44}
45
46/// Enables feature-specific code.
47/// Use this macro instead of `cfg(feature = "std")` to generate docs properly.
48#[macro_export]
49macro_rules! cfg_feature_std {
50    ($($item:item)*) => {
51        $(
52            #[cfg(any(all(doc, docsrs), feature = "std"))]
53            #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
54            $item
55        )*
56    }
57}
58
59/// Enables feature-specific code.
60/// Use this macro instead of `cfg(feature = "std")` to generate docs properly.
61#[macro_export]
62macro_rules! cfg_feature_nostd {
63    ($($item:item)*) => {
64        $(
65            #[cfg(any(all(doc, docsrs), not(feature = "std")))]
66            $item
67        )*
68    }
69}
70
71/// Enables feature-specific code.
72/// Use this macro instead of `cfg(feature = "alloc")` to generate docs properly.
73#[macro_export]
74macro_rules! cfg_feature_alloc {
75    ($($item:item)*) => {
76        $(
77            #[cfg(any(all(doc, docsrs), feature = "alloc"))]
78            #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
79            $item
80        )*
81    }
82}
83
84/// Enables feature-specific code.
85/// Use this macro instead of `cfg(feature = "serde")` to generate docs properly.
86#[macro_export]
87macro_rules! cfg_feature_serde {
88    ($($item:item)*) => {
89        $(
90            #[cfg(any(all(doc, docsrs), feature = "serde"))]
91            #[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
92            $item
93        )*
94    }
95}
96
97/// Enables feature-specific code.
98/// Use this macro instead of `cfg(feature = "bits")` to generate docs properly.
99#[macro_export]
100macro_rules! cfg_feature_bits {
101    ($($item:item)*) => {
102        $(
103            #[cfg(any(all(doc, docsrs), feature = "bits"))]
104            #[cfg_attr(docsrs, doc(cfg(feature = "bits")))]
105            $item
106        )*
107    }
108}
109
110/// Enables feature-specific code.
111/// Use this macro instead of `cfg(feature = "egui")` to generate docs properly.
112#[macro_export]
113macro_rules! cfg_feature_egui {
114    ($($item:item)*) => {
115        $(
116            #[cfg(any(all(doc, docsrs), feature = "egui"))]
117            #[cfg_attr(docsrs, doc(cfg(feature = "egui")))]
118            $item
119        )*
120    }
121}
122
123/// Enables feature-specific code.
124/// Use this macro instead of `cfg(feature = "plots")` to generate docs properly.
125#[macro_export]
126macro_rules! cfg_feature_plots {
127    ($($item:item)*) => {
128        $(
129            #[cfg(any(all(doc, docsrs), feature = "plots"))]
130            #[cfg_attr(docsrs, doc(cfg(feature = "plots")))]
131            $item
132        )*
133    }
134}
135
136/// Enables feature-specific code.
137/// Use this macro instead of `cfg(feature = "git")` to generate docs properly.
138#[macro_export]
139macro_rules! cfg_feature_git {
140    ($($item:item)*) => {
141        $(
142            #[cfg(any(all(doc, docsrs), feature = "git"))]
143            #[cfg_attr(docsrs, doc(cfg(feature = "git")))]
144            $item
145        )*
146    }
147}