1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(Searchable)]
pub fn searchable(input: TokenStream) -> TokenStream {
    // Parse the input tokens into a syntax tree
    let _input = parse_macro_input!(input as DeriveInput);

    // Build the output, possibly using quasi-quotation
    let expanded = quote! {
        struct Hello{};
        impl Hello {
            pub fn new() {
                ()
            }
        }
    };

    // Hand the output tokens back to the compiler
    TokenStream::from(expanded)
}