3 ms·
How do you format the arguments passed to println? Do you have to make new types just to do that?
by acqq 13y ago
How do you format the arguments passed to println? Do you have to make new types just to do that?
- mhaymo 13y agohttp://static.rust-lang.org/doc/master/std/fmt/index.html#formatting-parameters http://static.rust-lang.org/doc/master/std/fmt/index.html#fo... `println!("{:04d}", 1);` prints "0001". Is that what you're asking?
- Someone 13y agoI think that's what he is asking. Full details at http://static.rust-lang.org/doc/0.10/std/fmt/index.html http://static.rust-lang.org/doc/0.10/std/fmt/index.html By the way, the Rust docs look nice, but finding this was harder than it should be. After searching for 'println', I got at http://static.rust-lang.org/doc/0.10/std/index.html?search=Println http://static.rust-lang.org/doc/0.10/std/index.html?search=P..., which led me to http://static.rust-lang.org/doc/0.10/std/macros/macro.println.html http://static.rust-lang.org/doc/0.10/std/macros/macro.printl..., which says as good as nothing. The other search results (http://static.rust-lang.org/doc/0.10/std/io/stdio/fn.println.html http://static.rust-lang.org/doc/0.10/std/io/stdio/fn.println... and http://static.rust-lang.org/doc/0.10/std/io/stdio/fn.println_args.html http://static.rust-lang.org/doc/0.10/std/io/stdio/fn.println...) are similarly uninformative. It would have helped if the text "For more information, see std::fmt and std::io::stdio" on that first page had hyperlinks. Now, I had to search for "std::fmt" and wade through a sea of results to get at that first page.
- steveklabnik 13y agoMacro documentation is a little bit... off at the moment. :/
- acqq 13y agoYes. Now as it's mentioned "This is a programmer specified conversion which uses the `Show` trait, which works a bit like `toString` in Java." Do I get the content of { } passed to my custom Show, in order to implement all the formatting possibilities? Hint: explaining the mechanisms of handling such common tasks we can really learn a lot about the language. I'd be happy if the tutorial presents the solutions to such real and common tasks.