Struct Hand

Source
pub struct Hand {
    pub cards: Vec<Card>,
}
Expand description

A Hand is zero or more cards that represents some aspect of a game, e.g. the cards a person is holding. A hand may be shuffled or sorted and there are functions for adding or removing cards. Unlike a Deck, there is no concept of dealt or undealt cards.

Fields§

§cards: Vec<Card>

Implementations§

Source§

impl Hand

Source

pub fn new() -> Self

Create an empty hand

Source

pub fn from_hand(hand: &Hand) -> Hand

Makes a Hand from an existing hand

Source

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

Makes a Hand from a slice

Source

pub fn from_strings(card_slice: &[&str]) -> Hand

Constructs a Hand from a slice of strings with abbreviated card rank / suit values

Source

pub fn push_card(&mut self, card: Card)

Adds one Card to the Hand

Source

pub fn push_cards(&mut self, cards: &[Card])

Adds zero or more cards to the Hand

Source

pub fn push_hand(&mut self, other: &Hand)

Adds zero or more cards from some other Hand

Source

pub fn len(&self) -> usize

Returns the number of cards

Source

pub fn clear(&mut self)

Clears the Hand (makes it empty)

Source

pub fn remove(&mut self, index: usize) -> Card

Removes a Card from the Hand and returns it, panics if index does not exist

Source

pub fn remove_cards(&mut self, cards: &[Card])

Removes the first instance of every matching card from the Hand

Source

pub fn remove_all_cards(&mut self, cards: &[Card])

Removes the every instance of every matching card from the Hand

Source

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

Removes first instance of the matching card from the Hand

Source

pub fn cards_of_rank(&self, rank: Rank) -> Vec<Card>

Returns cards of the specified Rank

Source

pub fn cards_of_suit(&self, suit: Suit) -> Vec<Card>

Returns cards of the specified Suit

Trait Implementations§

Source§

impl<'a> AddAssign<&'a Hand> for Hand

Source§

fn add_assign(&mut self, rhs: &Hand)

Performs the += operation. Read more
Source§

impl AddAssign<Card> for Hand

Source§

fn add_assign(&mut self, rhs: Card)

Performs the += operation. Read more
Source§

impl Cards for Hand

Source§

fn cards(&self) -> &[Card]

Return the cards as a slice
Source§

fn mut_cards(&mut self) -> &mut [Card]

Return the cards as a mutable slice
Source§

fn shuffle(&mut self)

Shuffle the cards into a random order
Source§

fn sort_suit_ascending_rank(&mut self)

Sort the cards by suit and then by rank (low to high)
Source§

fn sort_suit_descending_rank(&mut self)

Sorts the cards by suit and then by rank (high to low)
Source§

fn sort_descending_rank_suit(&mut self)

Sort the cards by rank (high to low) and then by suit
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 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

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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>,

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V