Allow shorthand when passing params to templates

This commit is contained in:
Olivier 'reivilibre' 2023-03-04 10:42:52 +00:00 committed by Olivier 'reivilibre
parent e6cc7ef606
commit 63d03f3afb
2 changed files with 8 additions and 1 deletions

View File

@ -40,7 +40,7 @@ async fn main() -> eyre::Result<()> {
async fn say_hello(Path((lang, name)): Path<(String, String)>) -> impl IntoResponse {
Rendered(render_template_string!(TEMPLATING, say_hello, lang, {
name: name
name
}))
}

View File

@ -216,8 +216,15 @@ macro_rules! interpreter_setters {
{ $params:ident; $k:ident : $v:expr } => {
$params = $params.set(stringify!($k), $v);
};
{ $params:ident; $k:ident } => {
$params = $params.set(stringify!($k), $k);
};
{ $params:ident; $k:ident : $v:expr, $($tail:tt)* } => {
$params = $params.set(stringify!($k), $v);
interpreter_setters!{ $params; $($tail)* }
};
{ $params:ident; $k:ident, $($tail:tt)* } => {
$params = $params.set(stringify!($k), $k);
interpreter_setters!{ $params; $($tail)* }
};
}