So I've been using Rust recently and I'm coming to like it, however, I've come to notice that one of the biggest flaws ( at least in my opinion ) is the lack of any templating. I know there is the.format() that looks very ugly and horrible to read.
if I had any suggestion or constructive advice ( whatever that might be worth ), have it something like this.
println!($"hello my name is {name} and i'm {age} years old"). Something like that. Much more elegant than having to do this
println!("Hello, my name is {} and I am {} years old", name, age);
println!(), print!(), format!(), ... and all functions using formatting support using variable directly since Rust 1.58 (early 2022). It's just not mentioned in every documentation yet.
Note that it only works with variable names. Not general expression as in JS.
Which I personally find odd-but-good, because my experience seems to indicate that using general expressions within string templates quickly results in an unreadable mess.
I keep meaning to publish an alternative implementation that does support arbitrary expressions, it's relatively easy to do as a proc-macro, and personally I find that the expanded expressiveness is a net positive when used well (just like all language features, it can be abused, but that's what code reviews are for).
What do you plan to do about derive macros embedded into strings? And if that isn't allowed, what rules are there for the expressions that are supported?
I see no issues with them, as long as it’s a valid expression it should work (so they’d have to be wrapped into a block to declare any items). I at least would certainly reject a PR hiding an item inside an interpolation though.
My recollection was not that the RFC explicitly rejected this being changed in the future; just that it did not propose doing so initially. (EDIT: and at least the text of the RFC only refers to the authors opinion on the extension, if there was some consensus to reject in the discussion that was not recorded).
I'd love to see at least field access expressions supported... I feel like printing fields of structs is very common, and currently there is a somewhat awkward cliff between formatting a local variable and a field.