cup_cli/
utils.rs

1use std::collections::HashMap;
2
3pub fn template_f<'a, T: Into<HashMap<&'a str, String>>>(template: &str, replace: T) -> String {
4    let mut result = template.to_string();
5    let replace_map: HashMap<&str, String> = replace.into();
6    for (key, value) in replace_map {
7        result = result.replace(key, &value);
8    }
9    result
10}
11
12#[macro_export]
13macro_rules! write_template {
14    ($f:expr, $p:expr) => {
15        $f.write_fmt(format_args!("{}", include_str!($p)))
16    };
17    ($f:expr, $p: expr => [$($k: ident = $e: expr);+ $(;)?]) => {
18        $f.write_fmt(format_args!("{}", $crate::utils::template_f(include_str!($p), [$((constcat::concat!("{{", stringify!($k), "}}"), $e),)*])))
19    }
20}