[rust-dev] Why does string formatting in Rust have to be different from other languages?
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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Why does string formatting in Rust have to be different from other languages?
On Mon, Nov 18, 2013 at 2:02 AM, Derek Chiang derekchian...@gmail.com 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 It's the syntax used by C# and modern Python: http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx http://docs.python.org/2/library/string.html#format-string-syntax ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Why does string formatting in Rust have to be different from other languages?
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 derekchian...@gmail.com 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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev