interpolate icon indicating copy to clipboard operation
interpolate copied to clipboard

Question about nesting

Open Boscop opened this issue 7 years ago • 1 comments

In JS:

var x = 1;
var a = "asd"
var s = `a ${a + ` x${x + 1} y`} b`;
console.log(s); // a asd x2 y b

Would this be the Rust equivalent?

let x = 1;
let a = "asd";
let s = s!("a ${a.to_string() + &s!(" x${x + 1} y")} b");

or alternatively:

let x = 1;
let a = s!("asd");
let s = s!("a ${a + &s!(" x${x + 1} y")} b");

?

Boscop avatar Jul 27 '18 16:07 Boscop

Perhaps? But those are so complicated to read that they feel like the antithesis of what this crate aims to accomplish: interpolation that is very simple and natural to read and write. I had a hard time reading any of those examples. I'd prefer:

let nested = s!("{a} x{x+1} y");
let s = s!("a {nested} b");

(note: I'm using syntax that removes the $)

anowell avatar Jul 30 '18 08:07 anowell