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

13
mono-fmt-macro/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "mono-fmt-macro"
version = "0.1.0"
edition = "2021"
[lib]
proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
quote = "1.0.21"
syn = "1.0.99"

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()
}