क्या enum मूल्यों को प्रारूपित और प्रिंट करने का कोई आसान तरीका है? मुझे उम्मीद थी कि उनके पास std::fmt::Display
का डिफ़ॉल्ट कार्यान्वयन होगा, लेकिन ऐसा लगता है कि यह मामला नहीं है।क्या एनम वैल्यू प्रिंट करने का कोई तरीका है?
enum Suit {
Heart,
Diamond,
Spade,
Club
}
fn main() {
let s: Suit = Suit::Heart;
println!("{}", s);
}
वांछित उत्पादन: Heart
त्रुटि:
error[E0277]: the trait bound `Suit: std::fmt::Display` is not satisfied
--> src/main.rs:10:20
|
10 | println!("{}", s);
| ^the trait `std::fmt::Display` is not implemented for `Suit`
|
= note: `Suit` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
= note: required by `std::fmt::Display::fmt`
जंग में एक डिफ़ॉल्ट कार्यान्वयन के रूप में ऐसी कोई चीज नहीं है। –