aboutsummaryrefslogtreecommitdiff
path: root/macros/src/injectable/macro_args.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-08-03 15:09:46 +0200
committerHampusM <hampus@hampusmat.com>2023-08-03 15:15:29 +0200
commita3ccc2713bb5315123814cadd6c50275eee38e1c (patch)
tree22d50e174f3181bbddfd50840408e85e5a4adaac /macros/src/injectable/macro_args.rs
parent14f1fc1837675e1771e220f848b46213462ae804 (diff)
feat: add constructor name flag to injectable macro
Diffstat (limited to 'macros/src/injectable/macro_args.rs')
-rw-r--r--macros/src/injectable/macro_args.rs47
1 files changed, 32 insertions, 15 deletions
diff --git a/macros/src/injectable/macro_args.rs b/macros/src/injectable/macro_args.rs
index 6964352..ee398fc 100644
--- a/macros/src/injectable/macro_args.rs
+++ b/macros/src/injectable/macro_args.rs
@@ -7,8 +7,12 @@ use crate::macro_flag::MacroFlag;
use crate::util::error::diagnostic_error_enum;
use crate::util::iterator_ext::IteratorExt;
-pub const INJECTABLE_MACRO_FLAGS: &[&str] =
- &["no_doc_hidden", "async", "no_declare_concrete_interface"];
+pub const INJECTABLE_MACRO_FLAGS: &[&str] = &[
+ "no_doc_hidden",
+ "async",
+ "no_declare_concrete_interface",
+ "constructor",
+];
pub struct InjectableMacroArgs
{
@@ -21,9 +25,9 @@ impl InjectableMacroArgs
pub fn check_flags(&self) -> Result<(), InjectableMacroArgsError>
{
for flag in &self.flags {
- if !INJECTABLE_MACRO_FLAGS.contains(&flag.flag.to_string().as_str()) {
+ if !INJECTABLE_MACRO_FLAGS.contains(&flag.name().to_string().as_str()) {
return Err(InjectableMacroArgsError::UnknownFlag {
- flag_ident: flag.flag.clone(),
+ flag_ident: flag.name().clone(),
});
}
}
@@ -32,8 +36,8 @@ impl InjectableMacroArgs
self.flags.iter().find_duplicate()
{
return Err(InjectableMacroArgsError::DuplicateFlag {
- first_flag_ident: dupe_flag_first.flag.clone(),
- last_flag_span: dupe_flag_second.flag.span(),
+ first_flag_ident: dupe_flag_first.name().clone(),
+ last_flag_span: dupe_flag_second.name().span(),
});
}
@@ -111,9 +115,10 @@ mod tests
use proc_macro2::Span;
use quote::{format_ident, quote};
- use syn::{parse2, LitBool};
+ use syn::{parse2, Lit, LitBool};
use super::*;
+ use crate::macro_flag::MacroFlagValue;
use crate::test_utils;
#[test]
@@ -174,12 +179,18 @@ mod tests
injectable_macro_args.flags,
Punctuated::from_iter([
MacroFlag {
- flag: format_ident!("no_doc_hidden"),
- is_on: LitBool::new(true, Span::call_site())
+ name: format_ident!("no_doc_hidden"),
+ value: MacroFlagValue::Literal(Lit::Bool(LitBool::new(
+ true,
+ Span::call_site()
+ )))
},
MacroFlag {
- flag: format_ident!("async"),
- is_on: LitBool::new(false, Span::call_site())
+ name: format_ident!("async"),
+ value: MacroFlagValue::Literal(Lit::Bool(LitBool::new(
+ false,
+ Span::call_site()
+ )))
}
])
);
@@ -202,12 +213,18 @@ mod tests
injectable_macro_args.flags,
Punctuated::from_iter([
MacroFlag {
- flag: format_ident!("async"),
- is_on: LitBool::new(false, Span::call_site())
+ name: format_ident!("async"),
+ value: MacroFlagValue::Literal(Lit::Bool(LitBool::new(
+ false,
+ Span::call_site()
+ )))
},
MacroFlag {
- flag: format_ident!("no_declare_concrete_interface"),
- is_on: LitBool::new(false, Span::call_site())
+ name: format_ident!("no_declare_concrete_interface"),
+ value: MacroFlagValue::Literal(Lit::Bool(LitBool::new(
+ false,
+ Span::call_site()
+ )))
}
])
);