rust-cookbook
rust-cookbook copied to clipboard
Recipe: Implement Display, Debug for custom type
trafficstars
| Crates | std |
| Section | 16.2 String Parsing |
Given a simple custom type, implement debug and display directly. Do not lean on derive. Similar to this: https://doc.rust-lang.org/1.6.0/std/fmt/trait.Display.html#examples
It is OK for the cookbook to have similar examples to other sources, as this may be the first place someone looks to solve this problem. Do not use an x,y point as the example though. Mixed data types would be ideal.
Let's throw Hash on the sample too.
I'll take this one if it isn't claimed!
Would you like a simple implementation, or would you like to also see some of extra formatter flags used?