This commit is contained in:
nora 2022-09-11 21:47:43 +02:00
parent 83331e5326
commit ce5aa95a09
4 changed files with 199 additions and 6 deletions

31
mono-fmt-macro/src/lib.rs Normal file
View file

@ -0,0 +1,31 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{
parse::{Parse, ParseStream},
Expr, parse_macro_input,
};
struct Input {
format_str: String,
items: Vec<Expr>,
}
impl Parse for Input {
fn parse(input: ParseStream) -> syn::Result<Self> {
let first = input.parse::<syn::LitStr>()?;
Ok(Self {
format_str: first.value(),
items: Vec::new(),
})
}
}
#[proc_macro]
pub fn format_args(tokens: TokenStream) -> TokenStream {
let input = parse_macro_input!(tokens as Input);
let str = input.format_str;
quote! {
(mono_fmt::_private::Str(#str),)
}
.into()
}