Struct onejoker::cards::deck::Deck

source ·
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

source

pub fn new(dname: &str) -> Deck

Create a new deck from a MasterDeck by name. Filled but not shuffled.

source

pub fn new_hand(&self) -> Hand

Create a new Hand associated with the same MasterDeck, and deal it some initial cards.

source

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.

source

pub fn to_vec(&self) -> Vec<Card>

Export the current contents of the deck as a vector of Card.

source

pub fn deal_to(&mut self, h: &mut Hand, n: usize) -> bool

Deal n cards from the deck to the given Hand.

source

pub fn valid_card(&self, card: Card) -> Option<Card>

Validate that the give card is legal for this deck, or panic if not.

source

pub fn refill(&mut self)

Refill the deck from the master list.

source

pub fn len(&self) -> usize

Return the number of cards remaining in the deck.

source

pub fn remaining(&self) -> usize

Alias for len().

source

pub fn size(&self) -> usize

Return the total number of cards in the full deck.

source

pub fn is_empty(&self) -> bool

Is the deck empty?

source

pub fn is_not_empty(&self) -> bool

Is the deck not empty?

source

pub fn contains(&self, card: Card) -> bool

Does the deck contain the given Card?

source

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.

source

pub fn pop(&mut self) -> Option<Card>

Pop a Card from the deck. Return None if the deck is empty.

source

pub fn push_n<I>(&mut self, n: usize, cards: I)
where I: IntoIterator<Item = Card>,

Push a collection of Cards onto the deck.

source

pub fn pop_n(&mut self, n: usize) -> impl Iterator<Item = Card>

Pop n cards from the deck as an iterator.

source

pub fn remove_card(&mut self, card: Card) -> bool

Remove a card from the deck by value. Return true if found.

source

pub fn shuffle(&mut self)

Shuffle the deck in place.

source

pub fn sort(&mut self)

Sort the deck in place. This uses the same sort as the Hand class, so it’s technically descending by rank, but recall that Decks are printed in reverse, so it will look ascending.

source

pub fn combinations(&self, k: usize) -> impl Iterator<Item = Hand>

Iterate

source§

impl Deck

source

pub fn iter(&self) -> CardIter

Create a new iterator over the deck.

Trait Implementations§

source§

impl Clone for Deck

source§

fn clone(&self) -> Deck

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Deck

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Deck

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Deck

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Deck

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> aResult<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<'a> IntoIterator for &'a Deck

§

type Item = Card

The type of the elements being iterated over.
§

type IntoIter = CardIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> CardIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Deck

§

type Item = Card

The type of the elements being iterated over.
§

type IntoIter = CardIntoIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> CardIntoIter

Creates an iterator from a value. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.