Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice post. For some reason I can never remember the syntax for formatting and I have to look it up each time. I’ll bookmark your post for the next time I need this.


It might help you to remember that the syntax is `{identifier:flags}` where identifier being left blank signifies a positional argument to the formatting macro. Although if it's the specific flags you're having trouble remembering, I can't help you as I can't remember them either except `?` (debug print) and `#?` (pretty debug print).


A little hack: if you know the C-style format string you want to use, use that. The build will fail, of course, but Rust will tell you what to use instead.


Even more: those suggestions that you see when calling cargo/rustc? They are also applicable through a tooltip with rust-analyzer. rustc has json output where the substitutions are represented in a machine-friendly format. :)


Thanks Nico!



Thanks really appreciate it, happy to be in someone's bookmarks




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: