soliterm-model 0.1.0

Shared model types for soliterm
Documentation
use enum_map::Enum;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Color {
    Black,
    Red,
}

/// Enum representing the valid ranks for a card. The values for cards are a fixed set, so we use
/// an enum rather than a dumb wrapper around `u8`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Enum)]
#[repr(u8)]
pub enum Rank {
    Ace,
    Two,
    Three,
    Four,
    Five,
    Six,
    Seven,
    Eight,
    Nine,
    Ten,
    Jack,
    Queen,
    King,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Enum)]
#[repr(u8)]
pub enum Suit {
    Spades,
    Hearts,
    Diamonds,
    Clubs,
}

impl Suit {
    pub fn color(self) -> Color {
        match self {
            Self::Spades | Self::Clubs => Color::Black,
            Self::Hearts | Self::Diamonds => Color::Red,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Enum)]
pub struct Card {
    pub rank: Rank,
    pub suit: Suit,
}

impl Card {
    pub fn color(self) -> Color {
        self.suit.color()
    }
}