pub struct Deck {
pub master: &'static MasterDeck,
pub cards: Vec<Card>,
}
Expand description
wiki | “Live” deck of cards for play. An array of Card objects with methods appropriate for a deck of cards. Note that cards are pop()’d from end of the array for speed, making that notionally the “top” of the deck. We show the Deck reversed when printing for this reason to bake debugging easier. Cards in the deck are not accessed randomly by index, though they can be removed by value.
Fields§
§master: &'static MasterDeck
Static pointer to associated MasterDeck
cards: Vec<Card>
Current contents of the deck
Implementations§
source§impl Deck
impl Deck
sourcepub fn new(dname: &str) -> Deck
pub fn new(dname: &str) -> Deck
Create a new deck from a MasterDeck by name. Filled but not shuffled.
sourcepub fn new_hand(&self) -> Hand
pub fn new_hand(&self) -> Hand
Create a new Hand associated with the same MasterDeck, and deal it some initial cards.
sourcepub fn new_hand_with(&mut self, n: usize) -> Hand
pub fn new_hand_with(&mut self, n: usize) -> Hand
Create a new Hand associated with the same MasterDeck, and deal it some initial cards.
sourcepub fn deal_to(&mut self, h: &mut Hand, n: usize) -> bool
pub fn deal_to(&mut self, h: &mut Hand, n: usize) -> bool
Deal n
cards from the deck to the given Hand.
sourcepub fn valid_card(&self, card: Card) -> Option<Card>
pub fn valid_card(&self, card: Card) -> Option<Card>
Validate that the give card is legal for this deck, or panic if not.
sourcepub fn is_not_empty(&self) -> bool
pub fn is_not_empty(&self) -> bool
Is the deck not empty?
sourcepub fn push(&mut self, card: Card)
pub fn push(&mut self, card: Card)
Push a Card onto the deck. We do not generally expects cards to go in this direction, but it is useful for testing and simulation.
sourcepub fn pop(&mut self) -> Option<Card>
pub fn pop(&mut self) -> Option<Card>
Pop a Card from the deck. Return None
if the deck is empty.
sourcepub fn push_n<I>(&mut self, n: usize, cards: I)where
I: IntoIterator<Item = Card>,
pub fn push_n<I>(&mut self, n: usize, cards: I)where
I: IntoIterator<Item = Card>,
Push a collection of Cards onto the deck.
sourcepub fn pop_n(&mut self, n: usize) -> impl Iterator<Item = Card>
pub fn pop_n(&mut self, n: usize) -> impl Iterator<Item = Card>
Pop n
cards from the deck as an iterator.
sourcepub fn remove_card(&mut self, card: Card) -> bool
pub fn remove_card(&mut self, card: Card) -> bool
Remove a card from the deck by value. Return true
if found.
sourcepub fn combinations(&self, k: usize) -> impl Iterator<Item = Hand>
pub fn combinations(&self, k: usize) -> impl Iterator<Item = Hand>
Iterate
Trait Implementations§
source§impl<'a> IntoIterator for &'a Deck
impl<'a> IntoIterator for &'a Deck
Auto Trait Implementations§
impl Freeze for Deck
impl RefUnwindSafe for Deck
impl Send for Deck
impl Sync for Deck
impl Unpin for Deck
impl UnwindSafe for Deck
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)