Skip to content

Commit

Permalink
Allow format_args! as argument to tr!
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorc committed Aug 1, 2024
1 parent 994da65 commit da81db6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),* ] };
Expand Down Expand Up @@ -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");
}
}

0 comments on commit da81db6

Please sign in to comment.