feat: add ad-hoc conversions conventions for card mod
authorMA Beaudet <ma@beaudet.xyz>
Tue, 9 Nov 2021 13:19:04 +0000 (14:19 +0100)
committerMA Beaudet <ma@beaudet.xyz>
Tue, 9 Nov 2021 13:19:04 +0000 (14:19 +0100)
src/card.rs

index cfdb93a..1d8f45f 100644 (file)
@@ -13,6 +13,10 @@ impl Cards {
     pub fn into_inner(self) -> Vec<u32> {
         self.0.into_iter().map(|c| c.into_inner()).collect()
     }
+
+    pub fn as_vec_card(&self) -> &Vec<Card> {
+        &self.0
+    }
 }
 
 impl FromStr for Cards {
@@ -39,7 +43,7 @@ impl std::fmt::Display for Cards {
 
 impl From<Cards> for Vec<u32> {
     fn from(c: Cards) -> Self {
-        c.0.into_iter().map(|c| c.into_inner()).collect()
+        Vec::from(c.into_inner())
     }
 }
 
@@ -56,6 +60,10 @@ impl Deck {
         self.0
     }
 
+    pub fn as_cards(&self) -> &Cards {
+        &self.0
+    }
+
     pub fn deal_with_rules(&mut self, rules: &Rules) -> Result<Cards, MyError> {
         let v = match rules {
             Rules::Classic => self.deal(5)?,
@@ -128,6 +136,10 @@ impl Card {
         self.0
     }
 
+    pub fn as_u32(&self) -> u32 {
+        self.0
+    }
+
     pub fn suit(&self) -> char {
         match (self.0 >> 12) & 0xF {
             0b1000 => 'c',