Is there a way to print enum values?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)