Rust’s old fmt! syntax also used % instead of {}. The reason for the switch was
to primarily support compatibility with an internationalization-style scheme of
string formatting. The main benefit of {} of % is that you can nest {} inside
of another format, whereas with % you’re limited to just one format. That being
said, this effort has not gone underway just yet.
As Daniel also pointed out, the syntax was drawn from other languages instead
of inventing one fresh, so it should be familiar to at least some programmers.
If you’re curious about how the format syntax works, there’s documentation
which can be found at http://static.rust-lang.org/doc/master/std/fmt/index.html.
Hope that clears up any confusion!
On Nov 17, 2013, at 11:02 PM, Derek Chiang <[email protected]> wrote:
> Hi all,
>
> I'm a newcomer to Rust. One of the things that I find confusing is the use
> of {} in formatted strings. In all other languages I've ever used, it's
> always %. So instead of writing "%d", you write "{:d}" in Rust. Why is this
> so? What benefits do we get?
>
> Thanks,
> Derek
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev