use syn;
use proc_macro2::TokenStream;
#[derive(Debug)]
pub(crate) struct Arg {
pub index: usize,
pub ident: Option<String>,
pub capture: Option<usize>,
pub ty: syn::Type,
}
impl Arg {
pub fn new(index: usize, ident: String, capture: Option<usize>, ty: syn::Type) -> Arg {
Arg {
index,
ident: Some(ident),
capture,
ty,
}
}
pub fn ty_only(index: usize, ty: syn::Type) -> Arg {
Arg {
index,
ty,
ident: None,
capture: None,
}
}
pub fn new_callsite(&self) -> TokenStream {
if let Some(idx) = self.capture {
quote! { __tw::codegen::CallSite::new_capture(#idx) }
} else if let Some(ref ident) = self.ident {
match &ident[..] {
"query_string" => quote! { __tw::codegen::CallSite::new_query_string() },
"body" => quote! { __tw::codegen::CallSite::new_body() },
header => {
let header = ::header::arg_to_header_name(header);
let header = header.as_str();
quote! { __tw::codegen::CallSite::new_header(#header) }
}
}
} else {
quote! { __tw::codegen::CallSite::new_unknown() }
}
}
}