1use proc_macro::TokenStream;
2use quote::quote;
3
4struct ReExportStringz<T: syn::parse::Parse> {
5 pub path: syn::Path,
6 pub other: T,
7}
8
9impl<T: syn::parse::Parse> syn::parse::Parse for ReExportStringz<T> {
10 fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
11 let path = input.parse()?;
12 let _: syn::Token![;] = input.parse()?;
13 let other = input.parse()?;
14 Ok(Self { path, other })
15 }
16}
17
18#[proc_macro]
19pub fn ident(input: TokenStream) -> TokenStream {
20 let ReExportStringz { path, other: name } =
21 syn::parse_macro_input!(input as ReExportStringz<syn::Ident>);
22 let name = name.to_string();
23 let name: Vec<_> = name
24 .chars()
25 .map(|ch| quote!( #path::Character<#ch> ))
26 .collect();
27 quote!( #path::__tuplez::tuple_t![ #( #name ),* ] ).into()
28}
29
30#[proc_macro]
31pub fn string(input: TokenStream) -> TokenStream {
32 let ReExportStringz { path, other: name } =
33 syn::parse_macro_input!(input as ReExportStringz<syn::LitStr>);
34 let name = name.value();
35 let name: Vec<_> = name
36 .chars()
37 .map(|ch| quote!( #path::Character<#ch> ))
38 .collect();
39 quote!( #path::__tuplez::tuple_t![ #( #name ),* ] ).into()
40}