|
@ -47,7 +47,9 @@ impl Parse for ConfigField { |
|
|
} else if lookahead.peek(Token![async]) { |
|
|
} else if lookahead.peek(Token![async]) { |
|
|
input.parse::<Token![async]>()?; |
|
|
input.parse::<Token![async]>()?; |
|
|
input.parse::<Token![:]>()?; |
|
|
input.parse::<Token![:]>()?; |
|
|
Ok(ConfigField::Async(input.parse()?)) |
|
|
Ok(ConfigField::Async(AsyncConf { |
|
|
|
|
|
functions: input.parse()?, |
|
|
|
|
|
})) |
|
|
} else { |
|
|
} else { |
|
|
Err(lookahead.error()) |
|
|
Err(lookahead.error()) |
|
|
} |
|
|
} |
|
@ -282,40 +284,62 @@ impl Parse for ErrorConfField { |
|
|
#[derive(Clone, Default, Debug)] |
|
|
#[derive(Clone, Default, Debug)] |
|
|
/// Modules and funcs that have async signatures
|
|
|
/// Modules and funcs that have async signatures
|
|
|
pub struct AsyncConf { |
|
|
pub struct AsyncConf { |
|
|
functions: HashMap<String, Vec<String>>, |
|
|
functions: AsyncFunctions, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)] |
|
|
|
|
|
pub enum AsyncFunctions { |
|
|
|
|
|
Some(HashMap<String, Vec<String>>), |
|
|
|
|
|
All, |
|
|
|
|
|
} |
|
|
|
|
|
impl Default for AsyncFunctions { |
|
|
|
|
|
fn default() -> Self { |
|
|
|
|
|
AsyncFunctions::Some(HashMap::default()) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl AsyncConf { |
|
|
impl AsyncConf { |
|
|
pub fn is_async(&self, module: &str, function: &str) -> bool { |
|
|
pub fn is_async(&self, module: &str, function: &str) -> bool { |
|
|
self.functions |
|
|
match &self.functions { |
|
|
.get(module) |
|
|
AsyncFunctions::Some(fs) => fs |
|
|
.and_then(|fs| fs.iter().find(|f| *f == function)) |
|
|
.get(module) |
|
|
.is_some() |
|
|
.and_then(|fs| fs.iter().find(|f| *f == function)) |
|
|
|
|
|
.is_some(), |
|
|
|
|
|
AsyncFunctions::All => true, |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Parse for AsyncConf { |
|
|
impl Parse for AsyncFunctions { |
|
|
fn parse(input: ParseStream) -> Result<Self> { |
|
|
fn parse(input: ParseStream) -> Result<Self> { |
|
|
let content; |
|
|
let content; |
|
|
let _ = braced!(content in input); |
|
|
let lookahead = input.lookahead1(); |
|
|
let items: Punctuated<AsyncConfField, Token![,]> = |
|
|
if lookahead.peek(syn::token::Brace) { |
|
|
content.parse_terminated(Parse::parse)?; |
|
|
let _ = braced!(content in input); |
|
|
let mut functions: HashMap<String, Vec<String>> = HashMap::new(); |
|
|
let items: Punctuated<AsyncConfField, Token![,]> = |
|
|
use std::collections::hash_map::Entry; |
|
|
content.parse_terminated(Parse::parse)?; |
|
|
for i in items { |
|
|
let mut functions: HashMap<String, Vec<String>> = HashMap::new(); |
|
|
let function_names = i |
|
|
use std::collections::hash_map::Entry; |
|
|
.function_names |
|
|
for i in items { |
|
|
.iter() |
|
|
let function_names = i |
|
|
.map(|i| i.to_string()) |
|
|
.function_names |
|
|
.collect::<Vec<String>>(); |
|
|
.iter() |
|
|
match functions.entry(i.module_name.to_string()) { |
|
|
.map(|i| i.to_string()) |
|
|
Entry::Occupied(o) => o.into_mut().extend(function_names), |
|
|
.collect::<Vec<String>>(); |
|
|
Entry::Vacant(v) => { |
|
|
match functions.entry(i.module_name.to_string()) { |
|
|
v.insert(function_names); |
|
|
Entry::Occupied(o) => o.into_mut().extend(function_names), |
|
|
|
|
|
Entry::Vacant(v) => { |
|
|
|
|
|
v.insert(function_names); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
Ok(AsyncFunctions::Some(functions)) |
|
|
|
|
|
} else if lookahead.peek(Token![*]) { |
|
|
|
|
|
let _: Token![*] = input.parse().unwrap(); |
|
|
|
|
|
Ok(AsyncFunctions::All) |
|
|
|
|
|
} else { |
|
|
|
|
|
Err(lookahead.error()) |
|
|
} |
|
|
} |
|
|
Ok(AsyncConf { functions }) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|