From 27f28de59944647d01d322b63c0acb6d0f67a2f6 Mon Sep 17 00:00:00 2001 From: MA Beaudet Date: Tue, 9 Nov 2021 14:19:04 +0100 Subject: [PATCH] feat: add ad-hoc conversions conventions for card mod --- src/card.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/card.rs b/src/card.rs index cfdb93a..1d8f45f 100644 --- a/src/card.rs +++ b/src/card.rs @@ -13,6 +13,10 @@ impl Cards { pub fn into_inner(self) -> Vec { self.0.into_iter().map(|c| c.into_inner()).collect() } + + pub fn as_vec_card(&self) -> &Vec { + &self.0 + } } impl FromStr for Cards { @@ -39,7 +43,7 @@ impl std::fmt::Display for Cards { impl From for Vec { 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 { 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', -- 2.20.1