aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-29 03:11:13 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-29 03:11:13 +0800
commit03003aec99fc00c2a079bad9fb4e721432a6e6f0 (patch)
tree3767548b240447c96e49ebd4519a9ae20d47626e /src/lib.rs
parent58307e49e24bbbff55846147d97fbe60054486cc (diff)
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
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs24
1 files changed, 20 insertions, 4 deletions
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 @@
//! <<<crate_name>>> => Some(<<<crate_name>>>::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),* $(,)?)),*