From 55b31ee792963b4c23eae95f2216891b00cd6a69 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 28 Feb 2026 13:59:22 +0800 Subject: Rename src/lib.rs to src/template.rs --- src/lib.rs | 71 --------------------------------------------------------- src/template.rs | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 src/lib.rs create mode 100644 src/template.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 2df8e46..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::collections::HashMap; - -pub mod expand; -pub mod test; - -#[derive(Default, Clone)] -pub struct Template { - pub(crate) template_str: String, - pub(crate) params: HashMap, - pub(crate) impl_params: HashMap>>, -} - -impl Template { - /// Add a parameter - pub fn insert_param(&mut self, name: String, value: String) { - self.params.insert(name, value); - } - - /// Add an implementation block and return a HashMap to set its parameters - pub fn add_impl(&mut self, impl_name: String) -> &mut Vec> { - self.impl_params - .entry(impl_name) - .or_insert_with(|| Vec::>::new()) - } -} - -impl From for Template { - fn from(s: String) -> Self { - Template { - template_str: s, - ..Default::default() - } - } -} - -impl std::fmt::Display for Template { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let cloned = self.clone(); - write!(f, "{}", cloned.expand().unwrap_or_default()) - } -} - -#[macro_export] -macro_rules! tmpl_param { - ($template:ident, $($key:ident = $value:expr),* $(,)?) => {{ - $( - $template.insert_param(stringify!($key).to_string(), $value.to_string()); - )* - }}; -} - -#[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 - }); - )* - )* - }}; -} diff --git a/src/template.rs b/src/template.rs new file mode 100644 index 0000000..2df8e46 --- /dev/null +++ b/src/template.rs @@ -0,0 +1,71 @@ +use std::collections::HashMap; + +pub mod expand; +pub mod test; + +#[derive(Default, Clone)] +pub struct Template { + pub(crate) template_str: String, + pub(crate) params: HashMap, + pub(crate) impl_params: HashMap>>, +} + +impl Template { + /// Add a parameter + pub fn insert_param(&mut self, name: String, value: String) { + self.params.insert(name, value); + } + + /// Add an implementation block and return a HashMap to set its parameters + pub fn add_impl(&mut self, impl_name: String) -> &mut Vec> { + self.impl_params + .entry(impl_name) + .or_insert_with(|| Vec::>::new()) + } +} + +impl From for Template { + fn from(s: String) -> Self { + Template { + template_str: s, + ..Default::default() + } + } +} + +impl std::fmt::Display for Template { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let cloned = self.clone(); + write!(f, "{}", cloned.expand().unwrap_or_default()) + } +} + +#[macro_export] +macro_rules! tmpl_param { + ($template:ident, $($key:ident = $value:expr),* $(,)?) => {{ + $( + $template.insert_param(stringify!($key).to_string(), $value.to_string()); + )* + }}; +} + +#[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 + }); + )* + )* + }}; +} -- cgit