chironaut 0.3.5

A poker game library for Texas Hold'em and other poker variants
Documentation
use std::fmt;
use serde::{Serialize, Deserialize};
use crate::card::Card;
use crate::evaluation::{evaluate_hand, HandEvaluation};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Hand {
    cards: Vec<Card>,
}

impl Hand {
    pub fn new() -> Self {
        Self { cards: Vec::new() }
    }
    
    pub fn with_cards(cards: Vec<Card>) -> Self {
        Self { cards }
    }
    
    pub fn add_card(&mut self, card: Card) {
        self.cards.push(card);
    }
    
    pub fn add_cards(&mut self, cards: &[Card]) {
        self.cards.extend_from_slice(cards);
    }
    
    pub fn cards(&self) -> &[Card] {
        &self.cards
    }
    
    pub fn clear(&mut self) {
        self.cards.clear();
    }
    
    pub fn len(&self) -> usize {
        self.cards.len()
    }
    
    pub fn is_empty(&self) -> bool {
        self.cards.is_empty()
    }
    
    pub fn evaluate(&self) -> HandEvaluation {
        evaluate_hand(&self.cards)
    }
}

impl fmt::Display for Hand {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "[")?;
        for (i, card) in self.cards.iter().enumerate() {
            if i > 0 {
                write!(f, " ")?;
            }
            write!(f, "{}", card)?;
        }
        write!(f, "]")
    }
}

impl Default for Hand {
    fn default() -> Self {
        Self::new()
    }
}