Struct onejoker::cards::hand::Hand

source ·
pub struct Hand {
    pub master: &'static MasterDeck,
    pub cards: Vec<Card>,
}
Expand description

wiki | Hand of cards A simple array of card objects with some utility methods. It is expected that most access will go through push/pop``, which are fast, though things line insertandremove` are available.

Fields§

§master: &'static MasterDeck

Associated MasterDeck

§cards: Vec<Card>

Current contents

Implementations§

source§

impl Hand

source

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

Create new Hand associated with the named MasterDeck.

source

pub fn from_slice(cards: &[Card]) -> Hand

Create a new Hand associated with the default MasterDeck containing the cards given in the iterator.

source

pub fn from_text(text: &str) -> Hand

Create a new Hand associated with the default MasterDeck containing the hand given in text form.

source

pub fn copy_from_slice(&self, cards: &[Card]) -> Hand

Create a new “sister” Hand with the Cards given as a slice.

source

pub fn copy_from_text(&self, text: &str) -> Hand

Create a new “sister” Hand with the Cards given as text.

source

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

Export Vec of Cards.

source

pub fn as_slice(&self) -> &[Card]

Point to a slice of the underlying Card array.

source

pub fn len(&self) -> usize

How many cards in the hand?

source

pub fn is_empty(&self) -> bool

Is the hand empty?

source

pub fn is_not_empty(&self) -> bool

Is the hand not empty?

source

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

Does the hand contain the given Card?

source

pub fn clear(&mut self)

Empty the hand

source

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

Given a Card, return the same card if valid for our MasterDeck or panic. Correct ace values if needed.

source

pub fn card_at(&self, index: usize) -> Option<Card>

Return the Card at the given index, or None if out of range.

source

pub fn set_card_at(&mut self, index: usize, card: Card) -> bool

Set the Card at the given index, or return false if out of range.

source

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

Push a Card onto the end of the hand.

source

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

Pop a Card from the end of the hand.

source

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

Push a collection of Cards onto the end of the hand.

source

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

Pop n Cards from the end of the hand.

source

pub fn insert_at(&mut self, index: usize, card: Card) -> bool

Insert a Card at the given index.

source

pub fn remove_at(&mut self, index: usize) -> Option<Card>

Remove the Card at the given index.

source

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

Remove the given Card from the hand if present.

source

pub fn truncate(&mut self, n: usize)

Truncate the Hand to the given length.

source

pub fn shuffle(&mut self)

Shuffle the Hand in place.

source

pub fn sort(&mut self)

Sort the Hand in place.

source

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

Return an iterator over all n-card combinations of the hand.

source

pub fn equals(&self, other: &Self) -> bool

Return true if the hands are identical: i.e., same cards in same order.

source

pub fn is_equivalent_to(&self, other: &Self) -> bool

Return true if the hands are equivalent: i.e., same cards in any order.

source

pub fn ace_fix(&mut self)

Fix the ace values in the Hand to match the MasterDeck.

source

pub fn draw(&mut self, n: usize, d: &mut Deck) -> bool

Take n cards from the given Deck and add them to the hand.

source

pub fn draw_card(&mut self, c: Card, d: &mut Deck) -> bool

Take the given Card from the Deck and add it to the hand.

source

pub fn draw_hand(&mut self, cl: &[Card], d: &mut Deck) -> bool

Take the given Cards from the Deck and add them to the hand.

source§

impl Hand

source

pub fn iter(&self) -> CardIter

Return an iterator over the Cards in the hand.

Trait Implementations§

source§

impl Clone for Hand

source§

fn clone(&self) -> Hand

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 Hand

source§

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

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

impl Default for Hand

source§

fn default() -> Self

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

impl Display for Hand

source§

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

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

impl FromStr for Hand

§

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 Index<usize> for Hand

§

type Output = Card

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Hand

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a Hand

§

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 Hand

§

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 Hand

§

impl RefUnwindSafe for Hand

§

impl Send for Hand

§

impl Sync for Hand

§

impl Unpin for Hand

§

impl UnwindSafe for Hand

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.