String template interpolation

Hi, everyone.

I want to know if Rust is currently considering implementing string template interpolation? Or what is the current state of string template interpolation?

Thank you.

AFAIK there are no plans to have any magic in actual string literals. Rust's solution for formatted strings is the format!() macro.

There were some discussions and prototypes for clever hacks adding actual code interpolation to the formatting syntax, but I don't think anything real has come out of that, since format!("{arg}", arg = code) is considered good enough.

1 Like

https://crates.io/crates/fstrings
https://crates.io/crates/ifmt
https://crates.io/crates/interpolate

You won't find anything in std beyond what @kornel showed

Not just good enough, but from a localization perspective, the only right thing to do. String interpolation/concatenation is extremely unfriendly to localization etc.

1 Like

Not every string is for human consumption. Rust's formatted strings are not suitable for localization, e.g. Slavic grammar around numbers and gendered verbs doesn't fit simple substitution. I've seen "localized" applications with weird word salads because all they had to work with was %1 and %2. Use fluent, it does it properly.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.