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
use self::lazy_format::LazyFormat; use proc_macro::TokenStream; use quote::ToTokens; use syn::parse_macro_input; /// Lazy format macro /// /// [`lazy_format!`] is syntax sugar of `Display`. /// /// The first form of [`lazy_format!`] receives closure as the only one /// argument. /// /// ```ignore /// lazy_format!(|f| ...); /// ``` /// /// it expands to: /// /// ```ignore /// Display(move |f| ...); /// ``` /// /// The second form of [`lazy_format!`] has a syntax identical to the syntax of /// [`format!`](std::fmt::format). See [`fmt`](std::fmt) for more information. /// /// ```ignore /// lazy_format!("...", arg0, arg1, ...); /// ``` /// /// it expands to: /// /// ```ignore /// Display(move |f| write!(f, "...", arg0, arg1, ...)); /// ``` #[proc_macro] pub fn lazy_format(input: TokenStream) -> TokenStream { let lazy_format = parse_macro_input!(input as LazyFormat); lazy_format.into_token_stream().into() } mod lazy_format;