woboq / tr

Translation tools for rust
58 stars 10 forks source link

Allow `format_args!` as argument to `tr!` #25

Closed rodrigorc closed 3 months ago

rodrigorc commented 3 months ago

Hi, again!

The tr! macro does not accept formatting parameters in its placeholders, that is ok, IMO a translation string is better without those. Then the natural thing to do would be to inject them by writing:

tr!("Hello {}", format_args!("{:?}", [1, 2, 3]));

Alas, this fails to compile with a cryptic:

error[E0716]: temporary value dropped while borrowed
   --> tr/src/lib.rs:527:36
    |
174 |             };
    |              - temporary value is freed at the end of this statement
175 |             format!("{}", fa)
    |                           -- borrow later used here

Actually, the doc about format_args! warns about not storing such a value in local variable.

Naturally, I could just use format!(), but format_args! is more efficient.

Fortunately, the fix is quite trivial, as the local variable fa was there only for code style.

ogoffart commented 3 months ago

Thanks a lot for all your fixes.

Let me know when your queue of fixes is done and I'll make a release on crates.io

rodrigorc commented 3 months ago

Let me know when your queue of fixes is done and I'll make a release on crates.io

Just one more. That will be the best and most controversial of all 😉.

BTW, thank you so much for this crate!