1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
/// Creates a `Card` and sets its rank / suit from its abbreviated string description. The description
/// is of the form "RS", Rank followed by Suit, e.g. "2D" for Two of Diamonds.
///
/// # Examples
///
/// Creates the Ace of Spades
///
/// ```
/// # #[macro_use] extern crate deckofcards;
/// # fn main() {
/// let card = card!("AS");
/// # }
/// ```
#[macro_export]
macro_rules! card {
    ($s:expr) => {
        {
            let cr = $crate::Card::from_str($s);
            cr.unwrap_or_else(|_| {
                panic!("Not a known card {}", $s);
            })
        }
    };
}

/// Creates a `Hand` of cards from the list of abbreviated cards string specified by rank / suit,
///
/// # Examples
///
/// Creates a hand containing the Queen of Hearts and Two of Diamonds.
///
/// ```
/// # #[macro_use] extern crate deckofcards;
/// # fn main() {
/// let hand = hand!("QH", "2D");
/// # }
/// ```
#[macro_export]
macro_rules! hand {
    () => {
        $crate::Hand::new()
    };
    ( $( $s:expr ),* ) => {
        {
            let mut hand = $crate::Hand::new();
            $(
                hand += card!($s);
            )*
            hand
        }
    };
}

/// Creates a new `Hand` that is the combination two hands into one hand. This does not consume
/// the original hands.
///
/// # Examples
///
/// Combine hand1 and hand2 into a new hand_combined.
///
/// ```
/// # #[macro_use] extern crate deckofcards;
/// # fn main() {
/// use deckofcards::Hand;
/// let hand1 = hand!("AS", "KD");
/// let hand2 = hand!("QH", "3C", "4S");
/// let hand_combined = combine_hands!(&hand1, &hand2);
/// # }
/// ```
#[macro_export]
macro_rules! combine_hands {
    ( $( $h: expr),* ) => {
        {
            let mut result = $crate::Hand::new();
            $(
                result += $h;
            )*
            result
        }
    }
}

/// Creates a standard deck of 52 playing cards
#[macro_export]
macro_rules! deck {
    () => {
        $crate::Deck::new()
    }
}

mod suit;
pub use suit::{Suit};

mod rank;
pub use rank::{Rank};

mod card;
pub use card::{Card};

mod cards;
pub use cards::{Cards, cards_of_suit, cards_of_rank};

mod deck;
pub use deck::{Deck};

mod hand;
pub use hand::{Hand};

#[cfg(test)]
mod tests;