Enums in Rust can combine unit, tuple and named field variants to represent a wide range of concepts. This challenge uses enums to represent playing cards in a card game.
You will implement a Card
enum that can represent either:
King
, Queen
, Jack
), which is a unit variant.7 of Hearts
), which is a tuple variant.Create an enum Card
with the following variants:
King
, Queen
, Jack
(unit variants for face cards).Numbered(u8, String)
representing a numbered card with its value and suit.Write a function card_description
that takes a Card
and returns a description of the card:
King
, return "King"
.Queen
, return "Queen"
.Jack
, return "Jack"
.Numbered(value, suit)
, return "Numbered(value) of suit"
, e.g., "7 of Hearts"
.match
statement to handle each enum variant.format!
macro for the Numbered
variant.