osom_lib_macros/
reexport.rs

1/// Reexports a module if a feature is enabled.
2///
3/// # Example
4/// Lets say we have a module `baz` that we want to reexport
5/// only when `test` feature is enabled.
6///
7/// We can simply do:
8///
9/// ```ignore
10/// use osom_lib_macros::reexport_if_feature;
11/// reexport_if_feature!("test", baz);
12/// ```
13///
14/// which will be expanded to:
15///
16/// ```ignore
17/// mod baz;
18///
19/// #[cfg(feature = "test")]
20/// #[cfg_attr(docsrs, doc(cfg(feature = "test")))]
21/// #[allow(unused_imports)]
22/// pub use baz::*;
23/// ```
24///
25/// The `docsrs` is a custom attribute that you can set to
26/// enable nightly features in the docs, like this:
27///
28/// ```
29/// #![cfg_attr(docsrs, feature(doc_cfg))]
30/// ```
31///
32/// and then pass `--cfg docsrs` to `RUSTFLAGS` and `RUSTDOCFLAGS`
33/// environment variables during docs build.
34#[macro_export]
35macro_rules! reexport_if_feature {
36    ($feature:literal, $mod_name:ident) => {
37        mod $mod_name;
38
39        #[cfg(feature = $feature)]
40        #[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
41        #[allow(unused_imports)]
42        pub use $mod_name::*;
43    };
44}