1use syn::token::Comma;
2
3use crate::*;
4
5#[derive(Debug, Clone)]
6pub enum CallOrClosure {
7 Call(ExprCall),
8 Closure(ExprClosure),
9}
10
11impl ToTokens for CallOrClosure {
12 fn to_tokens(&self, tokens: &mut TokenStream2) {
13 let output = match self {
14 CallOrClosure::Call(call) => call.to_token_stream(),
15 CallOrClosure::Closure(expr_closure) => expr_closure.to_token_stream(),
16 };
17
18 tokens.extend(output);
19 }
20}
21
22pub struct PunctuatedItems<T: Parse> {
23 pub inner: Vec<T>,
24}
25
26pub type PathsList = PunctuatedItems<Path>;
27pub type IdentsList = PunctuatedItems<Path>;
28
29impl<T: Parse> Parse for PunctuatedItems<T> {
30 fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
31 let mut inner = Vec::new();
32
33 while !input.is_empty() {
34 inner.push(input.parse()?);
35
36 if input.is_empty() {
37 break;
38 }
39 let _comma: Comma = input.parse()?;
40 }
41
42 Ok(Self { inner })
43 }
44}
45
46pub struct StringList {
47 pub list: Vec<String>,
48}
49
50impl Parse for StringList {
51 fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
52 let mut list: Vec<String> = Vec::new();
53
54 while !input.is_empty() {
55 list.push(input.parse::<LitStr>()?.value());
56
57 if input.is_empty() {
58 break;
59 }
60 let _comma: Comma = input.parse()?;
61 }
62
63 Ok(Self { list })
64 }
65}
66
67pub struct NumList {
68 pub list: Vec<i32>,
69}
70
71impl Parse for NumList {
72 fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
73 let mut list: Vec<i32> = Vec::new();
74
75 while !input.is_empty() {
76 list.push(input.parse::<LitInt>()?.base10_parse()?);
77
78 if input.is_empty() {
79 break;
80 }
81 let _comma: Comma = input.parse()?;
82 }
83
84 Ok(Self { list })
85 }
86}