#[derive(Debug, Default, Clone)]
pub struct Cards(pub(crate) Vec<Card>);
+impl Cards {
+ pub fn into_inner(self) -> Vec<u32> {
+ self.0.into_iter().map(|c| c.into_inner()).collect()
+ }
+}
+
impl FromStr for Cards {
type Err = MyError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
impl From<Cards> for Vec<u32> {
fn from(c: Cards) -> Self {
- c.0.into_iter().map(|c| u32::from(c)).collect()
+ c.0.into_iter().map(|c| c.into_inner()).collect()
}
}
Self::default()
}
- pub fn get_with_rules(&mut self, rules: &Rules) -> Result<Cards, MyError> {
+ pub fn into_inner(self) -> Cards {
+ self.0
+ }
+
+ pub fn deal_with_rules(&mut self, rules: &Rules) -> Result<Cards, MyError> {
let v = match rules {
- Rules::Classic => self.get(5)?,
+ Rules::Classic => self.deal(5)?,
- Rules::Holdem => self.get(2)?,
+ Rules::Holdem => self.deal(2)?,
};
Ok(v)
}
- pub fn get_with_rules_and_player_nb(
+ pub fn deal_with_rules_and_player_nb(
&mut self,
rules: &Rules,
player_nb: usize,
) -> Result<Vec<Cards>, MyError> {
(0..player_nb)
.into_iter()
- .map(|_| Ok(self.get_with_rules(rules)?))
+ .map(|_| Ok(self.deal_with_rules(rules)?))
.collect()
}
- pub fn get(&mut self, n: usize) -> Result<Cards, MyError> {
+ pub fn deal(&mut self, n: usize) -> Result<Cards, MyError> {
if self.0 .0.len() < n {
Err(MyError::IndexError)
} else {
pub struct Card(pub(crate) u32);
impl Card {
- pub fn get(&self) -> u32 {
+ pub fn into_inner(self) -> u32 {
self.0
}
}
}
-impl From<Card> for u32 {
- fn from(c: Card) -> Self {
- c.0
- }
-}
-
impl TryFrom<u32> for Card {
type Error = MyError;
Self::default()
}
- pub fn with_rules<'a>(&'a mut self, rules: &Rules) -> &'a mut Evaluator {
+ pub fn rules<'a>(&'a mut self, rules: &Rules) -> &'a mut Evaluator {
self.rules = *rules;
self
}
- pub fn with_algorithm<'a>(&'a mut self, algorithm: &Algorithm) -> &'a mut Evaluator {
+ pub fn algorithm<'a>(&'a mut self, algorithm: &Algorithm) -> &'a mut Evaluator {
self.algorithm = *algorithm;
self
}
- pub fn with_hand<'a>(&'a mut self, hand: &Cards) -> &'a mut Evaluator {
self.hands.push(Rc::new(hand.clone()));
+ pub fn hand<'a>(&'a mut self, hand: &Cards) -> &'a mut Evaluator {
self
}
- pub fn with_hands<'a>(&'a mut self, hands: &Vec<Cards>) -> &'a mut Evaluator {
for hand in hands {
self.hands.push(Rc::new(hand.clone()))
}
+ pub fn hands<'a>(&'a mut self, hands: &Vec<Cards>) -> &'a mut Evaluator {
self
}
- pub fn with_table<'a>(&'a mut self, table: &Cards) -> &'a mut Evaluator {
self.table = Rc::new(table.clone());
+ pub fn table<'a>(&'a mut self, table: &Cards) -> &'a mut Evaluator {
self
}