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
use syn;
use proc_macro2::TokenStream;
pub fn print_err(msg: String, t: TokenStream) {
println!("Error: {} in '{}'", msg, t.to_string());
}
pub fn get_doc(attrs: &Vec<syn::Attribute>, null_terminated: bool) -> syn::Lit {
let mut doc = Vec::new();
for attr in attrs.iter() {
if let Some(syn::Meta::NameValue(ref metanv)) = attr.interpret_meta() {
if metanv.ident == "doc" {
if let syn::Lit::Str(ref litstr) = metanv.lit {
let d = litstr.value();
doc.push(if d.starts_with(" ") {
d[1..d.len()].to_string()
} else {
d
});
} else {
panic!("could not parse doc");
}
}
}
}
let doc = doc.join("\n");
syn::parse_str(&if null_terminated {
format!("\"{}\0\"", doc)
} else {
format!("\"{}\"", doc)
})
.unwrap()
}