How to implement indented display trait for struct or enum

fmt::Formatter has helper methods to implement this sort of thing for Debug implementations. You could use a newtype to wrap your Display-implementing types in such a way that they use the Display implementation for Debug output, and then use that in combination with the helpers.

Then you can get indended output when you use the "alternative" format ("{:#}").

2 Likes