News for hackers. Stuff that matters.
Re:Format Strings in Rust 1.58 by samwillis on Friday January 14, 2022 @06:29AM (#29933163)
What I particularly like about Pythons new(ish) “f strings” is that, firstly it’s opt in, you have to mark your strings with the “f” prefix. Secondly it is converted to opcodes at compile time, so f strings can’t be modified at runtime unlike standard “old fashioned” Python string interpolation.

As someone noted in another comment, this with Rust is effectively opt in with the println! and format! macros. Does it converted to machine code at compile time?

Re:Format Strings in Rust 1.58 by kimundi on Friday January 14, 2022 @09:46AM (#29935048)
Yes, the macros parse the string at compiletime and generate code that does the formatting as given by them. Here is an example for how the code would look like expanded: https://play.rust-lang.org/?version=stable&mode=debug&editio...