aboutsummaryrefslogtreecommitdiff
path: root/macros/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-31 13:26:41 +0200
committerHampusM <hampus@hampusmat.com>2022-08-01 15:52:23 +0200
commit3383faeaf8342cf4637b6d9a9dfba30b1684edca (patch)
tree3a4e23d299d077eaf82cb09a093eaaae384e4ec2 /macros/src/lib.rs
parent8d2c6412fec2f35581a48433421db4b03a8d6657 (diff)
feat: add hide impl of Injectable from documentation
This will make it so that by default the impl of Injectable is hidden from user code documentation. This commit also includes a flag for the injectable macro to disable the aforementioned feature
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r--macros/src/lib.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index aca4007..7dba7d1 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -14,16 +14,21 @@ mod factory_type_alias;
mod injectable_impl;
mod injectable_macro_args;
mod libs;
+mod util;
use declare_interface_args::DeclareInterfaceArgs;
use injectable_impl::InjectableImpl;
use injectable_macro_args::InjectableMacroArgs;
use libs::intertrait_macros::gen_caster::generate_caster;
-/// Makes a struct injectable. Thereby usable with `DIContainer`.
+/// Makes a struct injectable. Thereby usable with [`DIContainer`].
///
/// # Arguments
/// * (Optional) A interface trait the struct implements.
+/// * (Zero or more) Flags wrapped in curly braces. Like `{ a = true, b = false }`
+///
+/// # Flags
+/// - `no_doc_hidden` - Don't hide the impl of the [`Injectable`] trait from documentation.
///
/// # Panics
/// If the attributed item is not a impl.
@@ -53,15 +58,19 @@ use libs::intertrait_macros::gen_caster::generate_caster;
#[proc_macro_attribute]
pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenStream
{
- let should_declare_interface = !args_stream.is_empty();
+ let InjectableMacroArgs { interface, flags } = parse_macro_input!(args_stream);
- let injectable_impl: InjectableImpl = parse(impl_stream).unwrap();
+ let mut flags_iter = flags.iter();
- let expanded_injectable_impl = injectable_impl.expand();
+ let no_doc_hidden = flags_iter
+ .find(|flag| flag.flag.to_string().as_str() == "no_doc_hidden")
+ .map_or(false, |flag| flag.is_on.value);
+
+ let injectable_impl: InjectableImpl = parse(impl_stream).unwrap();
- let maybe_decl_interface = if should_declare_interface {
- let InjectableMacroArgs { interface } = parse_macro_input!(args_stream);
+ let expanded_injectable_impl = injectable_impl.expand(no_doc_hidden);
+ let maybe_decl_interface = if interface.is_some() {
let self_type = &injectable_impl.self_type;
quote! {