I'm trying to figure out why this works or rather how it works?
parse_terminated
is an associated function assigned to the variable-name parser
. How are we able to call the parse function on it? Or is parser
a sort of function type for which we automatically implement the Parser trait by calling .
operator on parser
#![allow(non_snake_case)]
use proc_macro::TokenStream;
// use quote::quote;
use syn::parse::Parser;
// use syn::parse_macro_input;
use syn::punctuated::Punctuated;
use syn::{Expr, Token};
#[proc_macro]
pub fn ConvertTo(input: TokenStream) -> TokenStream {
// Code Parse Phase
// println!("{:?}", input);
let tokens = input.clone();
let parser = Punctuated::<Expr, Token![,]>::parse_terminated;
let buff = match parser.parse(tokens) {
Ok(v) => v,
Err(_e) => panic!(),
};
println!("{:#?}", buff);
TokenStream::new()
}