Logo

Programming-Idioms

History of Idiom 55 > diff from v68 to v69

Edit summary for version 69 by Ericston:
[Rust] to_string is more expressive; no macro use

Version 68

2018-03-13, 20:43:20

Version 69

2019-07-08, 20:21:22

Idiom #55 Convert integer to string

Create the string representation s (in radix 10) of integer value i.

Illustration

Idiom #55 Convert integer to string

Create the string representation s (in radix 10) of integer value i.

Illustration
Extra Keywords
int base radix conversion
Extra Keywords
int base radix conversion
Code
let s = format!("{}", i);
Code
let s = i.to_string();
Doc URL
http://doc.rust-lang.org/std/fmt/index.html
Doc URL
https://doc.rust-lang.org/std/primitive.u32.html#impl-ToString
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20i%20%3D%2042%3B%0A%20%20%20%20let%20s%20%3D%20format!(%22%7B%7D%22%2C%20i)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%7D%22%2C%20s)%3B%0A%7D%0A&version=stable
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20i%20%3D%2042%3B%0A%20%20%20%20let%20s%20%3D%20format!(%22%7B%7D%22%2C%20i)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%7D%22%2C%20s)%3B%0A%7D%0A&version=stable