From 06db94de5861fcce5ff3e7dc4e5966293ef80ff3 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Mon, 31 Jul 2023 20:23:25 +0200 Subject: [PATCH] feat(core): slightly optimized `tr!` macro --- src/i18n.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/i18n.rs b/src/i18n.rs index 27cb3ae..db92643 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -109,15 +109,14 @@ macro_rules! tr { use fluent_templates::Loader; use fluent_templates::fluent_bundle::FluentValue; - let mut args = std::collections::HashMap::new(); - - for (key, value) in $args { - args.insert(key, FluentValue::from(value)); - } - #[allow(unused_unsafe)] $crate::i18n::LOCALES - .lookup_with_args(unsafe { &$crate::i18n::LANG }, $id, &args) + .lookup_with_args( + unsafe { &$crate::i18n::LANG }, + $id, + &std::collections::HashMap::from_iter($args.into_iter() + .map(|(key, value)| (key, FluentValue::from(value)))) + ) .expect(&format!("Failed to find a message with given id: {}", stringify!($id))) } };