Macro poker::card [−][src]
macro_rules! card { ($rank:ident, $suit:ident) => { ... }; ($rank:ident of $suit:ident) => { ... }; ($card_string:expr) => { ... }; }
A utility macro for creating a single card.
Examples
Use card!
with a capitalized rank and suit in order to get a
const
-friendly card. The capitalization is because the names fill in as
enum variant names for Rank
and Suit
use poker::{card, Card, Rank, Suit}; const ACE_OF_SPADES: Card = card!(Ace, Spades); assert_eq!(ACE_OF_SPADES, Card::new(Rank::Ace, Suit::Spades));
Alternatively, you can separate the rank and suit with of
for more
readability.
use poker::{card, Card, Rank, Suit}; const ACE_OF_SPADES: Card = card!(Ace of Spades); assert_eq!(ACE_OF_SPADES, Card::new(Rank::Ace, Suit::Spades));
Finally, you can pass in a string expression, which will result in a call to
parse()
. This, then, results in a Result
and will fail if the rank is
not one of “23456789TJQKA” and the suit is not one of “chsd”. This is
case-sensitive!
use poker::{card, Card, Rank, Suit}; let ace_of_spades = card!("As").expect("couldn't parse card"); assert_eq!(ace_of_spades, Card::new(Rank::Ace, Suit::Spades));