• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Pretty print struct in Rust

Resolved: Pretty print struct in Rust

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

How to print structs and arrays? – how does one pretty print a rust struct or any data type?
Sure, one can write the custom Debug method. But is there some way which enables the print by default?
One option is to use: https://docs.rs/pretty-trait/latest/pretty_trait/

Answer:

When you implement Debug, Rust provides “pretty printing” with {:#?}. From the std::fmt documentation:

# – This flag indicates that the “alternate” form of printing should be used. The alternate forms are: {:#?} – pretty-print the Debug formatting (adds linebreaks and indentation) [others omitted]


Example:
Output:
Playground

If you have better answer, please add a comment about this, thank you!

rust
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.