anowell / interpolate

Very simple Rust string interpolation
MIT License
36 stars 3 forks source link

Question about nesting #4

Open Boscop opened 6 years ago

Boscop commented 6 years ago

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");

?

anowell commented 6 years ago

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 $)