1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
extern crate proc_macro;

use proc_macro::TokenStream;
use std::str::FromStr;

#[proc_macro_attribute]
pub fn entity(_attr: TokenStream, item: TokenStream) -> TokenStream {
    item
}

#[proc_macro_attribute]
pub fn middleware(_attr: TokenStream, mut item: TokenStream) -> TokenStream {
    if !item.to_string().trim().starts_with("pub") {
        let s = "pub ".to_string() + &item.to_string();
        item= TokenStream::from_str(&s).unwrap();
        println!("item: {}", item.to_string());
    }
    item
}

#[proc_macro_attribute]
pub fn pipeline(_attr: TokenStream, mut item: TokenStream) -> TokenStream {
    if !item.to_string().trim().starts_with("pub") {
        let s = "pub ".to_string() + &item.to_string();
        item= TokenStream::from_str(&s).unwrap();
    }
    item
}

#[proc_macro_attribute]
pub fn spider(_attr: TokenStream, mut item: TokenStream) -> TokenStream {
    if !item.to_string().trim().starts_with("pub") {
        let s = "pub ".to_string() + &item.to_string();
        item= TokenStream::from_str(&s).unwrap();
    }
    item
}

#[proc_macro_attribute]
pub fn parser(_attr: TokenStream, mut item: TokenStream) -> TokenStream {
    if !item.to_string().trim().starts_with("pub") {
        let s = "pub ".to_string() + &item.to_string();
        item= TokenStream::from_str(&s).unwrap();
    }
    item
}