Skip to content

Commit

Permalink
Reduced amount of explicit clones in CardDeck
Browse files Browse the repository at this point in the history
  • Loading branch information
Nydauron committed Jun 28, 2024
1 parent 48c8502 commit 0fc3fb6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/core/carddeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ impl CardDeck {
/// Returns back a list of cards that were removed from the deck. Duplicates can be present in
/// the returned vector if duplicates existed in the deck.
pub fn strip_cards(&mut self, cards_to_remove: &HashSet<Card>) -> Vec<Card> {
let removed_cards: Vec<Card> = self
let removed_cards = self
.deck
.clone()
.into_iter()
.iter()
.filter(|card| cards_to_remove.contains(card))
.cloned()
.collect();

self.deck.retain(|card| !cards_to_remove.contains(card));
Expand All @@ -218,11 +218,11 @@ impl CardDeck {
/// Returns back a list of cards that were removed from the deck. Duplicates can be present in
/// the returned vector if duplicates existed in the deck.
pub fn strip_ranks(&mut self, ranks_to_remove: &HashSet<Value>) -> Vec<Card> {
let removed_cards: Vec<Card> = self
let removed_cards = self
.deck
.clone()
.into_iter()
.iter()
.filter(|card| ranks_to_remove.contains(&card.value))
.cloned()
.collect();

self.deck
Expand All @@ -236,11 +236,11 @@ impl CardDeck {
/// Returns back a list of cards that were removed from the deck. Duplicates can be present in
/// the returned vector if duplicates existed in the deck.
pub fn strip_suits(&mut self, suits_to_remove: &HashSet<Suit>) -> Vec<Card> {
let removed_cards: Vec<Card> = self
let removed_cards = self
.deck
.clone()
.into_iter()
.iter()
.filter(|card| suits_to_remove.contains(&card.suit))
.cloned()
.collect();

self.deck
Expand Down Expand Up @@ -339,7 +339,7 @@ impl CardDeck {
if !self.check_deal_cards(
cards_to_deal
- discard_cards
.clone()
.as_ref()
.map_or(0, |v| if include_muck { v.len() } else { 0 }),
include_muck,
) {
Expand Down

0 comments on commit 0fc3fb6

Please sign in to comment.