format_macro/lib.rs
1use self::lazy_format::LazyFormat;
2use proc_macro::TokenStream;
3use quote::ToTokens;
4use syn::parse_macro_input;
5
6/// Lazy format macro
7///
8/// [`lazy_format!`] is syntax sugar of `Display`.
9///
10/// The first form of [`lazy_format!`] receives closure as the only one
11/// argument.
12///
13/// ```ignore
14/// lazy_format!(|f| ...);
15/// ```
16///
17/// it expands to:
18///
19/// ```ignore
20/// Display(move |f| ...);
21/// ```
22///
23/// The second form of [`lazy_format!`] has a syntax identical to the syntax of
24/// [`format!`](std::fmt::format). See [`fmt`](std::fmt) for more information.
25///
26/// ```ignore
27/// lazy_format!("...", arg0, arg1, ...);
28/// ```
29///
30/// it expands to:
31///
32/// ```ignore
33/// Display(move |f| write!(f, "...", arg0, arg1, ...));
34/// ```
35#[proc_macro]
36pub fn lazy_format(input: TokenStream) -> TokenStream {
37 let lazy_format = parse_macro_input!(input as LazyFormat);
38 lazy_format.into_token_stream().into()
39}
40
41mod lazy_format;