You can derive an implementation of std::format::Debug
:
#[derive(Debug)]
enum Suit {
Heart,
Diamond,
Spade,
Club
}
fn main() {
let s = Suit::Heart;
println!("{:?}", s);
}
It is not possible to derive Display
because Display
is aimed at displaying to humans and the compiler cannot automatically decide what is an appropriate style for that case. Debug
is intended for programmers, so an internals-exposing view can be automatically generated.