diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-24 13:13:20 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-24 13:13:20 +0200 |
commit | 695f90bf900015df1e2728445f833dabced838a9 (patch) | |
tree | c68f2b483e3d20f400d27d4df159b2aec94d072f /macros/src/decl_def_factory_args.rs | |
parent | 3ed020425bfd1fc5fedfa89a7ce20207bedcf5bc (diff) |
refactor: reorganize modules in the macros crate
Diffstat (limited to 'macros/src/decl_def_factory_args.rs')
-rw-r--r-- | macros/src/decl_def_factory_args.rs | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/macros/src/decl_def_factory_args.rs b/macros/src/decl_def_factory_args.rs deleted file mode 100644 index 6450583..0000000 --- a/macros/src/decl_def_factory_args.rs +++ /dev/null @@ -1,56 +0,0 @@ -use syn::parse::Parse; -use syn::punctuated::Punctuated; -use syn::{Token, Type}; - -use crate::macro_flag::MacroFlag; -use crate::util::iterator_ext::IteratorExt; - -pub const FACTORY_MACRO_FLAGS: &[&str] = &["threadsafe"]; - -pub struct DeclareDefaultFactoryMacroArgs -{ - pub interface: Type, - pub flags: Punctuated<MacroFlag, Token![,]>, -} - -impl Parse for DeclareDefaultFactoryMacroArgs -{ - fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> - { - let interface = input.parse().unwrap(); - - if !input.peek(Token![,]) { - return Ok(Self { - interface, - flags: Punctuated::new(), - }); - } - - input.parse::<Token![,]>().unwrap(); - - 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 { interface, flags }) - } -} |