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
#![doc(html_root_url = "https://docs.rs/rhizome_proc-macro-definitions/0.0.1")]
#![forbid(unsafe_code)]
#![warn(clippy::pedantic)]
#![allow(clippy::too_many_lines)]

extern crate proc_macro;

mod extractable_declaration;

use {
    extractable_declaration::ExtractableDeclaration,
    lazy_static::lazy_static,
    proc_macro::TokenStream as TokenStream1,
    proc_macro2::{Span, TokenStream as TokenStream2},
    proc_macro_crate::crate_name,
    syn::{parse_macro_input, Ident},
};

#[proc_macro]
pub fn extractable(input: TokenStream1) -> TokenStream1 {
    let extractable_declaration = parse_macro_input!(input as ExtractableDeclaration);
    let tokens: TokenStream2 = extractable_declaration
        .into_tokens()
        .unwrap_or_else(|error| error.to_compile_error());
    tokens.into()
}

lazy_static! {
    static ref RHIZOME_NAME: String =
        crate_name("rhizome").unwrap_or_else(|_| "rhizome".to_owned());
}
fn rhizome_ident(span: Span) -> Ident {
    Ident::new(&*RHIZOME_NAME, span)
}