aboutsummaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-02 19:32:25 +0200
committerHampusM <hampus@hampusmat.com>2022-10-02 19:32:25 +0200
commitd8525f169649e4ce7e806e68de5e328135755326 (patch)
tree4fc573e79c8f3836fada5fdb0851b4740a63c43d /macros
parent31f62ea0c634360030dcf89203268fa5684b5905 (diff)
refactor: improve management of feature specific items
Diffstat (limited to 'macros')
-rw-r--r--macros/Cargo.toml2
-rw-r--r--macros/src/lib.rs15
2 files changed, 9 insertions, 8 deletions
diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index e65a4d7..205e9fe 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -13,6 +13,7 @@ proc_macro = true
[package.metadata.docs.rs]
all-features = true
+rustdoc-args = ["--cfg", "doc_cfg"]
[features]
factory = []
@@ -25,6 +26,7 @@ proc-macro2 = "1.0.40"
uuid = { version = "0.8", features = ["v4"] }
regex = "1.6.0"
once_cell = "1.13.1"
+feature_macros = "0.1.0"
[dev_dependencies]
syrette = { version = "0.4.0", path = "..", features = ["factory"] }
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index fc30016..8e906d0 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -1,3 +1,5 @@
+#![cfg_attr(doc_cfg, feature(doc_cfg))]
+#![feature(proc_macro_hygiene)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
@@ -5,6 +7,7 @@
//! Macros for the [Syrette](https://crates.io/crates/syrette) crate.
+use feature_macros::feature_specific;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse, parse_macro_input};
@@ -15,10 +18,10 @@ mod libs;
mod macro_flag;
mod util;
-#[cfg(feature = "factory")]
+#[feature_specific("factory")]
mod factory;
-#[cfg(feature = "factory")]
+#[feature_specific("factory")]
mod fn_trait;
use crate::declare_interface_args::DeclareInterfaceArgs;
@@ -156,8 +159,6 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
///
/// The return type is automatically put inside of a [`TransientPtr`].
///
-/// *This macro is only available if Syrette is built with the "factory" feature.*
-///
/// # Arguments
/// * (Zero or more) Flags. Like `a = true, b = false`
///
@@ -192,8 +193,8 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// ```
///
/// [`TransientPtr`]: https://docs.rs/syrette/latest/syrette/ptr/type.TransientPtr.html
+#[feature_specific("factory")]
#[proc_macro_attribute]
-#[cfg(feature = "factory")]
pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> TokenStream
{
use quote::ToTokens;
@@ -267,8 +268,6 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke
/// Another way to accomplish what this macro does would be by using
/// the [`macro@factory`] macro.
///
-/// *This macro is only available if Syrette is built with the "factory" feature.*
-///
/// # Arguments
/// - Interface trait
/// * (Zero or more) Flags. Like `a = true, b = false`
@@ -292,7 +291,7 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke
/// declare_default_factory!(dyn IParser);
/// ```
#[proc_macro]
-#[cfg(feature = "factory")]
+#[feature_specific("factory")]
pub fn declare_default_factory(args_stream: TokenStream) -> TokenStream
{
use syn::parse_str;