From 3383faeaf8342cf4637b6d9a9dfba30b1684edca Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 31 Jul 2022 13:26:41 +0200 Subject: 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 --- macros/src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'macros/src/lib.rs') 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! { -- cgit v1.2.3-18-g5258