Struct stochasta::playing_cards::PlayingCardDeck
source · pub struct PlayingCardDeck { /* private fields */ }
Expand description
A builder for quickly creating decks of playing cards.
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.value_range(PlayingCardValue::Seven, PlayingCardValue::Ace)
.all_suits()
.set_count(2)
.to_deck();
println!("{:?}", deck);
assert_eq!(deck.size(), 64);
Implementations§
source§impl PlayingCardDeck
impl PlayingCardDeck
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new empty deck.
Example
use stochasta::playing_cards::PlayingCardDeck;
let deck = PlayingCardDeck::new();
assert!(deck.is_empty())
sourcepub fn set_values<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = PlayingCardValue>,
pub fn set_values<I>(self, values: I) -> Selfwhere I: IntoIterator<Item = PlayingCardValue>,
Sets the values.
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.set_values([PlayingCardValue::Ten, PlayingCardValue::Ace])
.set_suits([PlayingCardSuit::Hearts])
.to_deck();
assert_eq!(deck.size(), 2);
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ten, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ace, PlayingCardSuit::Hearts)));
sourcepub fn set_suits<I>(self, suits: I) -> Selfwhere
I: IntoIterator<Item = PlayingCardSuit>,
pub fn set_suits<I>(self, suits: I) -> Selfwhere I: IntoIterator<Item = PlayingCardSuit>,
Sets the suits.
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.set_values([PlayingCardValue::Ace])
.set_suits([PlayingCardSuit::Hearts, PlayingCardSuit::Clubs])
.to_deck();
assert_eq!(deck.size(), 2);
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ace, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ace, PlayingCardSuit::Clubs)));
sourcepub fn value_range(self, from: PlayingCardValue, to: PlayingCardValue) -> Self
pub fn value_range(self, from: PlayingCardValue, to: PlayingCardValue) -> Self
Sets the value range. (both inclusive)
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.value_range(PlayingCardValue::Jack, PlayingCardValue::Ace)
.set_suits([PlayingCardSuit::Hearts])
.to_deck();
assert_eq!(deck.size(), 4);
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Jack, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Queen, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::King, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ace, PlayingCardSuit::Hearts)));
sourcepub fn all_values(self) -> Self
pub fn all_values(self) -> Self
Sets all PlayingCardValue
s to be included.
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.all_values()
.set_suits([PlayingCardSuit::Hearts])
.to_deck();
assert_eq!(deck.size(), 13);
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Two, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ten, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Ace, PlayingCardSuit::Hearts)));
sourcepub fn all_suits(self) -> Self
pub fn all_suits(self) -> Self
Sets all PlayingCardSuit
s inclusive.
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.set_values([PlayingCardValue::Two])
.all_suits()
.to_deck();
assert_eq!(deck.size(), 4);
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Two, PlayingCardSuit::Diamonds)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Two, PlayingCardSuit::Hearts)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Two, PlayingCardSuit::Clubs)));
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Two, PlayingCardSuit::Spades)));
sourcepub fn set_count(self, count: u64) -> Self
pub fn set_count(self, count: u64) -> Self
Sets the count of each individual card.
Example
use stochasta::playing_cards::{PlayingCard, PlayingCardDeck, PlayingCardSuit, PlayingCardValue};
let deck = PlayingCardDeck::new()
.set_values([PlayingCardValue::Two])
.set_suits([PlayingCardSuit::Hearts])
.set_count(4)
.to_deck();
assert_eq!(deck.size(), 4);
assert!(deck.contains(&PlayingCard::new(PlayingCardValue::Two, PlayingCardSuit::Hearts)));
sourcepub fn to_deck(&self) -> CardDeck<PlayingCard>
pub fn to_deck(&self) -> CardDeck<PlayingCard>
Trait Implementations§
source§impl Clone for PlayingCardDeck
impl Clone for PlayingCardDeck
source§fn clone(&self) -> PlayingCardDeck
fn clone(&self) -> PlayingCardDeck
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PlayingCardDeck
impl Debug for PlayingCardDeck
source§impl Default for PlayingCardDeck
impl Default for PlayingCardDeck
source§impl<'de> Deserialize<'de> for PlayingCardDeck
impl<'de> Deserialize<'de> for PlayingCardDeck
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for PlayingCardDeck
impl Display for PlayingCardDeck
source§impl Hash for PlayingCardDeck
impl Hash for PlayingCardDeck
source§impl Ord for PlayingCardDeck
impl Ord for PlayingCardDeck
source§fn cmp(&self, other: &PlayingCardDeck) -> Ordering
fn cmp(&self, other: &PlayingCardDeck) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<PlayingCardDeck> for PlayingCardDeck
impl PartialEq<PlayingCardDeck> for PlayingCardDeck
source§fn eq(&self, other: &PlayingCardDeck) -> bool
fn eq(&self, other: &PlayingCardDeck) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<PlayingCardDeck> for PlayingCardDeck
impl PartialOrd<PlayingCardDeck> for PlayingCardDeck
source§fn partial_cmp(&self, other: &PlayingCardDeck) -> Option<Ordering>
fn partial_cmp(&self, other: &PlayingCardDeck) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for PlayingCardDeck
impl Serialize for PlayingCardDeck
impl Copy for PlayingCardDeck
impl Eq for PlayingCardDeck
impl StructuralEq for PlayingCardDeck
impl StructuralPartialEq for PlayingCardDeck
Auto Trait Implementations§
impl RefUnwindSafe for PlayingCardDeck
impl Send for PlayingCardDeck
impl Sync for PlayingCardDeck
impl Unpin for PlayingCardDeck
impl UnwindSafe for PlayingCardDeck
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
Mutably borrows from an owned value. Read more