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

Nice, I hope it will be improved to print the variable names as in Python f-string, something like "{x=}" generating "x=<value of x>", much better than having to write "x={x}" everywhere..


This is what the dbg! macro is for: https://doc.rust-lang.org/std/macro.dbg.html


Unfortunately the `dbg!` macro doesn't play nice with format strings. There is no Rust equivalent of Python's (say) `print(f"Coordinates: {x=}, {y=}, {z=}")`. In other words `dbg!` can only print `{x=}`; it can't intersperse that with other text the way `format!` can.


This should not be difficult to do yourself. That is, you should be able to provide an improved format! with this feature as say renox::format! and provide popular format-using macros like renox::println! and renox::print! too based on the existing code, simply using the same license as Rust's standard library.

Only the macro knows the name of the variable, so you can't do this inside the formatter itself.


Generally if you want that, the derived Debug impls are good enough, and then you can print the debug form with: "{x:?}" and that can be made to pretty print (newlines, etc) with "{x:#?}". That will print the entire structure of a type and its associated values (can be quite verbose, though).




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: