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
47
48
49
50
51
52
53
54
55
56
57
58
use darling::FromMeta;
use proc_macro::{self, TokenStream};
use syn::{parse_macro_input, spanned::Spanned};
mod client;
mod runtimes;
mod utils;
#[proc_macro_attribute]
pub fn tidext(attr: TokenStream, item: TokenStream) -> TokenStream {
if !attr.is_empty() {
let msg = "Invalid tidext macro call: expected no attributes, e.g. macro call must be just \
``#[tidext]`";
let span = proc_macro2::TokenStream::from(attr).span();
return syn::Error::new(span, msg).to_compile_error().into();
}
let item = syn::parse_macro_input!(item as syn::ItemMod);
match client::Def::try_from(item) {
Ok(def) => client::expand(def).into(),
Err(e) => e.to_compile_error().into(),
}
}
#[proc_macro_attribute]
pub fn runtimes(attr: TokenStream, item: TokenStream) -> TokenStream {
let span = proc_macro2::TokenStream::from(attr.clone()).span();
let attr_args = parse_macro_input!(attr as syn::AttributeArgs);
let item_mod = parse_macro_input!(item as syn::ItemMod);
let args = match runtimes::RuntimeMetadataArgs::from_list(&attr_args) {
Ok(v) => v,
Err(e) => return e.write_errors().into(),
};
match args.runtime_metadata_path.try_into() {
Ok(runtimes) => runtimes::expand(item_mod, runtimes).into(),
Err(e) => syn::Error::new(span, e.to_string())
.to_compile_error()
.into(),
}
}