We will add two derives, Getters and Setters. We will start with the first one by creating the required boilerplate:
extern crate proc_macro;extern crate syn;#[macro_use]extern crate quote;use proc_macro::TokenStream;#[proc_macro_derive(Getters)]pub fn derive_getters(input: TokenStream) -> TokenStream { // Parse the input tokens into a syntax tree let input = syn::parse(input).unwrap(); // Build the output let expanded = impl_getters(&input); // Hand the output tokens back to the compiler expanded.into()}fn impl_getters(ast: &syn::DeriveInput) -> quote::Tokens { let name = &ast.ident; unimplemented!()}
We will not only need the name of the structure, we will also need any further generics added to the structure and