use std::collections::HashMap; #[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()) } }