diff --git a/card_stuffs/Cargo.lock b/card_stuffs/Cargo.lock index 8f6115e..3c2d1e7 100644 --- a/card_stuffs/Cargo.lock +++ b/card_stuffs/Cargo.lock @@ -13,9 +13,17 @@ name = "card_stuffs" version = "0.1.0" dependencies = [ "anyhow", + "strum", + "strum_macros", "thiserror", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "proc-macro2" version = "1.0.93" @@ -34,6 +42,31 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + +[[package]] +name = "strum" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32" + +[[package]] +name = "strum_macros" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "syn" version = "2.0.98" diff --git a/card_stuffs/Cargo.toml b/card_stuffs/Cargo.toml index faa2a3b..0b792d8 100644 --- a/card_stuffs/Cargo.toml +++ b/card_stuffs/Cargo.toml @@ -5,4 +5,6 @@ edition = "2021" [dependencies] anyhow = "1.0.96" +strum = "0.27.1" +strum_macros = "0.27.1" thiserror = "2.0.11" diff --git a/card_stuffs/src/lib.rs b/card_stuffs/src/lib.rs index 2fd07e3..a72d17a 100644 --- a/card_stuffs/src/lib.rs +++ b/card_stuffs/src/lib.rs @@ -1,8 +1,9 @@ use thiserror::Error; -use anyhow::Result; +use strum::IntoEnumIterator; +use strum_macros::EnumIter; use std::fmt; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, EnumIter, Copy, Clone)] pub enum Suit { Heart, Diamond, @@ -38,7 +39,7 @@ impl fmt::Display for Suit { } } -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, EnumIter, Copy, Clone)] pub enum Value { Ace, Two, @@ -133,6 +134,30 @@ impl Card { } } +#[derive(Debug)] +pub struct Deck { + pub cards: Vec +} + +impl Default for Deck { + fn default() -> Deck { + let mut array = Vec::new(); + for suit in Suit::iter() { + for value in Value::iter() { + array.push( + Card { + suit: suit, + value: value, + } + ); + } + } + Deck { + cards: array, + } + } +} + #[cfg(test)] mod tests { @@ -173,4 +198,11 @@ mod tests { assert!(false, "Cards are not adjacent - should be an error") } } + + #[test] + fn get_a_whole_deck() { + let d = Deck::default(); + assert_eq!(d.cards.len(), 52); // Probably should test whether all cards are in... eh + println!("{:#?}", d); + } }