Struct deckofcards::Deck
source · pub struct Deck { /* private fields */ }
Expand description
The Deck
represents a deck of zero or more cards. Internally the
deck consists of an undealt and a dealt pile of cards. The undealt pile starts off empty and
receives cards as they are dealt from the undealt pile.
The deck may be reset to return it to its original state. A deck may be shuffled to randomize its order.
A deck can contain more than one card with the same rank / suit combination.
A deck cannot have more cards added or removed to it once it is created.
Implementations
sourceimpl Deck
impl Deck
sourcepub fn from_cards(cards: &[Card]) -> Deck
pub fn from_cards(cards: &[Card]) -> Deck
Creates a new Deck
containing the specified cards
sourcepub fn undealt_count(&self) -> usize
pub fn undealt_count(&self) -> usize
Returns the number of remaining undealt cards in the Deck
sourcepub fn dealt_count(&self) -> usize
pub fn dealt_count(&self) -> usize
Returns the number of dealt cards in the Deck
sourcepub fn dealt_cards(&self) -> &[Card]
pub fn dealt_cards(&self) -> &[Card]
Returns the collection of dealt cards
sourcepub fn top_card(&self) -> Option<Card>
pub fn top_card(&self) -> Option<Card>
Tells you the top card (very next to be drawn) in the undealt deck without dealing it.
sourcepub fn bottom_card(&self) -> Option<Card>
pub fn bottom_card(&self) -> Option<Card>
Tells you the bottom card (very last to be drawn) in the undealt deck without dealing it.
sourcepub fn deal_one(&mut self) -> Result<Card, &'static str>
pub fn deal_one(&mut self) -> Result<Card, &'static str>
Deals the card from the undealt pile. If there are no cards left, the function will return an error.
sourcepub fn deal(&mut self, numcards: usize) -> Vec<Card>
pub fn deal(&mut self, numcards: usize) -> Vec<Card>
Deals one or more card from the undealt pile and returns them as an array.
sourcepub fn deal_to_hand(&mut self, hand: &mut Hand, numcards: usize) -> usize
pub fn deal_to_hand(&mut self, hand: &mut Hand, numcards: usize) -> usize
Deals one or more card straight to the Hand
. Returns the number of cards dealt.
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Return the dealt cards back to the end of the undealt pile. Order is preserved according to the default order or the last shuffle.
sourcepub fn reset_shuffle(&mut self)
pub fn reset_shuffle(&mut self)
Resets and shuffles the deck