From da81db65d4fdfa0a8f01c888ae73614583d25cb1 Mon Sep 17 00:00:00 2001 From: Rodrigo Rivas Costa Date: Thu, 1 Aug 2024 19:30:57 +0200 Subject: [PATCH] Allow `format_args!` as argument to `tr!` --- tr/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tr/src/lib.rs b/tr/src/lib.rs index d2c3eb6..023561a 100644 --- a/tr/src/lib.rs +++ b/tr/src/lib.rs @@ -167,12 +167,11 @@ pub mod runtime_format { }}; ($fmt:expr, $($tail:tt)* ) => {{ let format_str = $fmt; - let fa = $crate::runtime_format::FormatArg { + format!("{}", $crate::runtime_format::FormatArg { format_str: AsRef::as_ref(&format_str), //args: &[ $( $crate::runtime_format!(@parse_arg $e) ),* ], args: $crate::runtime_format!(@parse_args [] $($tail)*) - }; - format!("{}", fa) + }) }}; (@parse_args [$($args:tt)*]) => { &[ $( $args ),* ] }; @@ -545,5 +544,7 @@ mod tests { tr!("ctx" => "{0} have one item" | "{0} have {n} items" % 42, "I"), "I have 42 items" ); + + assert_eq!(tr!("{} = {}", 255, format_args!("{:#x}", 255)), "255 = 0xff"); } }