aboutsummaryrefslogtreecommitdiff
path: root/macros/src/factory_macro_args.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-29 20:52:56 +0200
committerHampusM <hampus@hampusmat.com>2022-08-29 21:01:32 +0200
commit080cc42bb1da09059dbc35049a7ded0649961e0c (patch)
tree307ee564124373616022c1ba2b4d5af80845cd92 /macros/src/factory_macro_args.rs
parent6e31d8f9e46fece348f329763b39b9c6f2741c07 (diff)
feat: implement async functionality
Diffstat (limited to 'macros/src/factory_macro_args.rs')
-rw-r--r--macros/src/factory_macro_args.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/macros/src/factory_macro_args.rs b/macros/src/factory_macro_args.rs
new file mode 100644
index 0000000..57517d6
--- /dev/null
+++ b/macros/src/factory_macro_args.rs
@@ -0,0 +1,44 @@
+use syn::parse::Parse;
+use syn::punctuated::Punctuated;
+use syn::Token;
+
+use crate::macro_flag::MacroFlag;
+use crate::util::iterator_ext::IteratorExt;
+
+pub const FACTORY_MACRO_FLAGS: &[&str] = &["async"];
+
+pub struct FactoryMacroArgs
+{
+ pub flags: Punctuated<MacroFlag, Token![,]>,
+}
+
+impl Parse for FactoryMacroArgs
+{
+ fn parse(input: syn::parse::ParseStream) -> syn::Result<Self>
+ {
+ let flags = Punctuated::<MacroFlag, Token![,]>::parse_terminated(input)?;
+
+ for flag in &flags {
+ let flag_str = flag.flag.to_string();
+
+ if !FACTORY_MACRO_FLAGS.contains(&flag_str.as_str()) {
+ return Err(input.error(format!(
+ "Unknown flag '{}'. Expected one of [ {} ]",
+ flag_str,
+ FACTORY_MACRO_FLAGS.join(",")
+ )));
+ }
+ }
+
+ let flag_names = flags
+ .iter()
+ .map(|flag| flag.flag.to_string())
+ .collect::<Vec<_>>();
+
+ if let Some(dupe_flag_name) = flag_names.iter().find_duplicate() {
+ return Err(input.error(format!("Duplicate flag '{}'", dupe_flag_name)));
+ }
+
+ Ok(Self { flags })
+ }
+}