From 03003aec99fc00c2a079bad9fb4e721432a6e6f0 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 29 Jun 2026 03:11:13 +0800 Subject: feat: add CHANGELOG and simplify tmpl! macro syntax Introduce a CHANGELOG.md file and update the `tmpl!` macro to use a cleaner syntax with comma-separated key-value pairs instead of the `+=` operator and parentheses-wrapped parameters --- src/lib.rs | 24 ++++++++++++++++++++---- src/test.rs | 8 ++++---- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 704b310..cf9d66e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,12 +33,12 @@ //! <<>> => Some(<<>>::exec(data, params).await), //! @@@ <<< //! ".trim().to_string()); -//! tmpl!(tmpl += { +//! tmpl!(tmpl, //! arms { -//! (crate_name = "my"), -//! (crate_name = "you") +//! crate_name = "my", +//! crate_name = "you", //! } -//! }); +//! ); //! // Output the expanded template //! let expanded = tmpl.to_string(); //! assert_eq!(expanded, " @@ -63,6 +63,22 @@ macro_rules! tmpl_param { #[macro_export] macro_rules! tmpl { + ($template:ident, $($name:ident { + $($key:ident = $value:expr),* $(,)? + }),* $(,)?) => {{ + $( + let $name = $template.add_impl(stringify!($name).to_string()); + $( + $name.push({ + let mut params = std::collections::HashMap::new(); + params.insert(stringify!($key).to_string(), $value.to_string()); + params + }); + )* + )* + }}; + + // Old syntax ($template:ident += { $($name:ident { $(($($key:ident = $value:expr),* $(,)?)),* diff --git a/src/test.rs b/src/test.rs index a5ef801..91407fc 100644 --- a/src/test.rs +++ b/src/test.rs @@ -15,12 +15,12 @@ mod tests { let mut tmpl = Template::from(input); tmpl_param!(tmpl, func_name = "my_func"); - tmpl!(tmpl += { + tmpl!(tmpl, arms { - (crate_name = "my"), - (crate_name = "you") + crate_name = "my", + crate_name = "you", } - }); + ); let expanded = tmpl.expand().unwrap(); assert_eq!(expanded, expect); -- cgit