### Build WASM example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Builds the minimal browser-WASM example for testing wasm-friendly API patterns. ```bash cargo build --target wasm32-unknown-unknown --example wasm ``` -------------------------------- ### Run Hand and Foot example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Executes the Hand and Foot game example to demonstrate multi-deck support. ```bash cargo ex handandfoot ``` -------------------------------- ### Run range chart example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Prints a 13x13 starting-hand range chart. ```bash cargo ex range ``` -------------------------------- ### Run Poker example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Executes a random heads-up no-limit Poker deal. ```bash cargo ex poker ``` -------------------------------- ### Run Cardpack Examples Source: https://docs.rs/cardpack Commands to execute various card game demonstrations and build configurations. ```bash cargo ex handandfoot ``` ```bash cargo ex poker ``` ```bash cargo ex poker_eval ``` ```bash cargo ex range ``` ```bash cargo ex buffoon ``` ```bash cargo ex funky_tour ``` ```bash cargo build --target wasm32-unknown-unknown --example wasm ``` -------------------------------- ### Run Balatro scoring pipeline example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Executes the Balatro four-phase scoring pipeline. ```bash cargo ex buffoon ``` -------------------------------- ### Run funky engine tour example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Executes a seeded tour of the funky engine features. ```bash cargo ex funky_tour ``` -------------------------------- ### Retrieve Metadata Source: https://docs.rs/cardpack/0.9.0/cardpack/localization/trait.Named.html Examples for retrieving card weight and prime number metadata. ```rust use cardpack::localization::*; let queen = FluentName::new("queen"); assert_eq!(10, queen.weight()); ``` ```rust use cardpack::localization::*; let queen = FluentName::new("queen"); assert_eq!(31, queen.prime()); ``` -------------------------------- ### Run French Deck Demo Source: https://docs.rs/cardpack Display a 54-card French deck with jokers using the demo example. ```bash cargo ex demo -- --french -v ``` -------------------------------- ### Creating a BasicCard with Pips Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pips/struct.Pip.html Example demonstrating how to construct a BasicCard using two Pip instances to represent rank and suit. ```rust use cardpack::prelude::*; let trey_of_hearts = BasicCard { suit: Pip { weight: 2, pip_type: PipType::Suit, index: 'H', symbol: '♥', value: 3, }, rank: Pip { weight: 1, pip_type: PipType::Rank, index: '3', symbol: '3', value: 3, }, }; assert_eq!(trey_of_hearts, FrenchBasicCard::TREY_HEARTS); ``` -------------------------------- ### Run Bridge Hand Example Source: https://docs.rs/cardpack Generate and display a random bridge hand or convert a PBN deal string. ```bash cargo ex bridge ``` -------------------------------- ### Drawing the First Card Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic/struct.BasicPileCell.html Example of drawing the top card from a BasicPileCell. ```rust use cardpack::prelude::*; let pile = Pile::::basic_pile_cell(); let card = pile.draw_first().unwrap(); assert_eq!(card, FrenchBasicCard::ACE_SPADES); ``` -------------------------------- ### Run Scoring Pipeline and Tour Examples Source: https://docs.rs/cardpack Execute the scoring pipeline or a seeded tour using the cargo alias. ```bash cargo ex buffoon ``` ```bash cargo ex funky_tour ``` -------------------------------- ### Retrieve Index Values Source: https://docs.rs/cardpack/0.9.0/cardpack/localization/trait.Named.html Examples for retrieving the index representation of a card in different languages or as a default. ```rust use cardpack::localization::*; let jack = FluentName::new("jack"); assert_eq!("B", jack.index(&FluentName::DEUTSCH)); ``` ```rust use cardpack::localization::*; let jack = FluentName::new("jack"); assert_eq!('B', jack.index_char(&FluentName::DEUTSCH)); ``` ```rust use cardpack::localization::*; let ten = FluentName::new("ten"); assert_eq!("T", ten.index_default()); ``` -------------------------------- ### Retrieve Card Index String Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Get the basic text representation of a card. ```rust use cardpack::prelude::*; let card = Card::::new(SkatBasicCard::ZHEN_EICHEL); assert_eq!(card.index(), "ZE"); ``` -------------------------------- ### Run Poker evaluation example Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Scores a Texas Hold’em board using the ckc-rs evaluator. ```bash cargo ex poker_eval ``` -------------------------------- ### Retrieve All Decks Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/registry/enum.DeckKind.html Use the all() method to get a slice of all available deck variants. ```rust use cardpack::prelude::*; assert!(!DeckKind::all().is_empty()); assert!(DeckKind::all().contains(&DeckKind::French)); ``` -------------------------------- ### Shuffling a Pile Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic/struct.BasicPileCell.html Example of creating a shuffled version of a BasicPileCell. ```rust use cardpack::prelude::*; let pile = Pile::::basic_pile_cell(); // println!("{}", pile.shuffled()); ``` -------------------------------- ### Manual Rank Sorting Variants Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Examples showing different approaches to sorting by rank manually using standard library comparison functions. ```rust use std::str::FromStr; use cardpack::prelude::{Pile, Standard52}; let pack = Pile::::from_str("2♠ 8♠ 4♠").unwrap(); let mut v = pack.cards().clone(); v.sort_by(|a, b| a.base_card.rank.cmp(&b.base_card.rank)); assert_eq!(Pile::::from(v).to_string(), "2♠ 4♠ 8♠"); ``` ```rust use std::str::FromStr; use cardpack::prelude::{Pile, Standard52}; let pack = Pile::::from_str("2♠ 8♠ 4♠").unwrap(); let mut v = pack.cards().clone(); v.sort_by(|a, b| a.base_card.rank.cmp(&b.base_card.rank)); v.reverse(); assert_eq!(Pile::::from(v).to_string(), "8♠ 4♠ 2♠"); ``` ```rust use std::str::FromStr; use cardpack::prelude::{Pile, Standard52}; let pack = Pile::::from_str("2♠ 8♠ 4♠").unwrap(); let mut v = pack.cards().clone(); v.sort_by(|a, b| b.base_card.rank.cmp(&a.base_card.rank)); assert_eq!(Pile::::from(v).to_string(), "8♠ 4♠ 2♠"); ``` -------------------------------- ### Get Pile Index Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Returns the basic text representation of the pile. ```rust use cardpack::prelude::*; let pile = Pile::::from_str("T♥ Q♠ J♥").unwrap(); assert_eq!(pile.index(), "TH QS JH"); ``` -------------------------------- ### Retrieve Long Names Source: https://docs.rs/cardpack/0.9.0/cardpack/localization/trait.Named.html Examples for retrieving the full localized name of a card. ```rust use cardpack::localization::*; let big_joker = FluentName::new("big-joker"); assert_eq!("Großer Joker", big_joker.long(&FluentName::DEUTSCH)); ``` ```rust use cardpack::localization::*; let big_joker = FluentName::new("big-joker"); assert_eq!("Full-Color", big_joker.long_default()); ``` -------------------------------- ### Drawing Cards from a Pile Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic/struct.BasicPileCell.html Example of drawing a subset of cards from a BasicPileCell. ```rust use cardpack::prelude::*; let pile = Pile::::basic_pile_cell(); let drawn = pile.draw(5).unwrap(); assert_eq!(drawn.to_string(), "A♠ K♠ Q♠ J♠ T♠"); ``` -------------------------------- ### Use PipType for Conditional Logic Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pips/enum.PipType.html Example demonstrating how to use PipType to check for specific card types within a hand. ```rust use cardpack::prelude::*; let hand = french_cards!("A♠ B🃟 Q♠ J♠ T♠"); let optimal_hand = match hand.cards_of_suit_pip_type(PipType::Joker).len() { 0 => hand, _ => find_optimal_hand(hand), }; fn find_optimal_hand(hand: Pile) -> Pile { // Logic that returns the best scoring version of the hand with the joker. hand } ``` -------------------------------- ### Retrieve BasicCard index and string representation Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_card/struct.BasicCard.html Get the basic index string (e.g., JD) or the formatted display string (e.g., J♦) for a card. ```rust use cardpack::prelude::*; assert_eq!(FrenchBasicCard::JACK_DIAMONDS.index(), "JD"); assert_eq!(FrenchBasicCard::JACK_DIAMONDS.to_string(), "J♦"); ``` -------------------------------- ### Get Human-Readable Deck Name Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/registry/enum.DeckKind.html Retrieve the display name for a specific deck variant. ```rust use cardpack::prelude::*; assert_eq!(DeckKind::Standard52.deck_name(), "Standard 52"); assert_eq!(DeckKind::Tarot.deck_name(), "Tarot"); ``` -------------------------------- ### Handle into_cards slice warning Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/traits/trait.Decked.html Example of the compiler warning when using &Vec instead of a slice. ```rust warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do --> src/rev6/traits.rs:22:31 | 22 | fn into_cards(base_cards: &Vec) -> Vec> { | ^^^^^^^^^^^^^^ help: change this to: `&[BaseCard]` ``` -------------------------------- ### Get Card by Position Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Retrieves a reference to a card at a specific index, returning None if out of bounds. ```rust use cardpack::prelude::*; let pile = Pile::::deck(); assert_eq!(pile.get(3).unwrap(), &Card::::new(FrenchBasicCard::JACK_SPADES)); assert!(pile.get(99).is_none()); ``` -------------------------------- ### Filter cards by rank pip type Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/traits/trait.Ranged.html Examples and implementation for filtering a deck by rank pip type. ```rust use cardpack::prelude::*; let mut deck = French::deck(); assert_eq!(deck.cards_of_rank_pip_type(PipType::Joker).len(), 2); ``` ```rust #[must_use] pub fn cards_of_rank_pip_type(&self, pip_type: PipType) -> Self { self.iter() .filter(|card| card.rank.pip_type == pip_type) .cloned() .collect() } ``` -------------------------------- ### Checking if Pile is Empty Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic/struct.BasicPileCell.html Example of checking the emptiness of a BasicPileCell. ```rust use cardpack::prelude::*; let pile = Pile::::basic_pile_cell(); assert!(!pile.is_empty()); assert!(BasicPileCell::default().is_empty()); ``` -------------------------------- ### Get Pile Length Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Returns the number of cards in the pile. ```rust use cardpack::prelude::*; assert_eq!(French::deck().len(), 54); ``` -------------------------------- ### Taking the Pile Value Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic/struct.BasicPileCell.html Example of taking the underlying BasicPile out of the cell. ```rust use cardpack::prelude::*; let pile = Pile::::basic_pile_cell(); assert_eq!(Standard52::DECK_SIZE, pile.take().len()); assert_eq!(0, pile.take().len()); ``` -------------------------------- ### Initialize and Use a Standard52 Deck Source: https://docs.rs/cardpack Shows how to create a 52-card deck and use the card! and cards! macros for convenient card creation. ```rust use cardpack::prelude::*; let mut standard52_deck = Pile::::deck(); assert_eq!(standard52_deck.len(), 52); assert_eq!( standard52_deck.to_string(), "A♠ K♠ Q♠ J♠ T♠ 9♠ 8♠ 7♠ 6♠ 5♠ 4♠ 3♠ 2♠ A♥ K♥ Q♥ J♥ T♥ 9♥ 8♥ 7♥ 6♥ 5♥ 4♥ 3♥ 2♥ A♦ K♦ Q♦ J♦ T♦ 9♦ 8♦ 7♦ 6♦ 5♦ 4♦ 3♦ 2♦ A♣ K♣ Q♣ J♣ T♣ 9♣ 8♣ 7♣ 6♣ 5♣ 4♣ 3♣ 2♣" ); // It includes the card! and cards! macros for easy Standard52 card creation: assert_eq!(card!(AS), Card::::new(FrenchBasicCard::ACE_SPADES)); assert_eq!(cards!("AS KS QS JS TS"), standard52_deck.draw(5).unwrap()); ``` -------------------------------- ### Build Project with GNU Make Source: https://docs.rs/cardpack Uses the make utility to build and run common project tasks. ```makefile make ``` -------------------------------- ### Standard52 deck operations Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pile/struct.Pile.html Demonstrates deck initialization and basic card drawing. ```rust use cardpack::prelude::*; let mut deck = Standard52::deck(); assert_eq!(deck.ranks_index(" "), "A K Q J T 9 8 7 6 5 4 3 2"); assert_eq!(deck.suit_symbol_index(" "), "♠ ♥ ♦ ♣"); assert_eq!(deck.suits_index(" "), "S H D C"); assert_eq!(deck.draw(5).unwrap().to_string(), "A♠ K♠ Q♠ J♠ T♠"); assert_eq!(deck.len(), 47); ``` -------------------------------- ### Enable full features Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html Configuration to enable all library features including std, i18n, and serialization. ```toml full ``` -------------------------------- ### Removing Cards by Position Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic/struct.BasicPileCell.html Example of removing cards from specific indices in the pile. ```rust use cardpack::prelude::*; let pile = Pile::::basic_pile_cell(); let card = pile.remove(0); assert_eq!(card.to_string(), "A♠"); let card = pile.remove(50); assert_eq!(card.to_string(), "2♣"); assert_eq!( pile.to_string(), "K♠ Q♠ J♠ T♠ 9♠ 8♠ 7♠ 6♠ 5♠ 4♠ 3♠ 2♠ A♥ K♥ Q♥ J♥ T♥ 9♥ 8♥ 7♥ 6♥ 5♥ 4♥ 3♥ 2♥ A♦ K♦ Q♦ J♦ T♦ 9♦ 8♦ 7♦ 6♦ 5♦ 4♦ 3♦ 2♦ A♣ K♣ Q♣ J♣ T♣ 9♣ 8♣ 7♣ 6♣ 5♣ 4♣ 3♣" ); ``` -------------------------------- ### Get reversed pile Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Returns a new pile with the cards in reverse order. ```rust use cardpack::prelude::*; let pile = Euchre24::deck(); let reversed_pile = pile.reversed(); assert_eq!( reversed_pile.to_string(), "9♣ T♣ J♣ Q♣ K♣ A♣ 9♦ T♦ J♦ Q♦ K♦ A♦ 9♥ T♥ J♥ Q♥ K♥ A♥ 9♠ T♠ J♠ Q♠ K♠ A♠" ); ``` -------------------------------- ### Create Multiple Decks Source: https://docs.rs/cardpack Demonstrates creating multiple decks simultaneously, useful for games like Hand and Foot. ```rust use cardpack::prelude::*; let hand_and_foot_4players = French::decks(4); assert_eq!(hand_and_foot_4players.len(), 216); let hand_and_foot_5players = French::decks(5); assert_eq!(hand_and_foot_5players.len(), 270); ``` -------------------------------- ### Get Unique Cards Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Returns a BTreeSet of unique cards, collapsing duplicates. ```rust use std::collections::BTreeSet; use cardpack::prelude::*; // The 2♠ appears twice, but the BTreeSet only keeps one entry. let pile = Pile::::from_str("2♠ 8♠ 2♠ 4♠").unwrap(); let mut set: BTreeSet> = BTreeSet::new(); set.insert(card!(2S)); set.insert(card!(8S)); set.insert(card!(4S)); assert_eq!(pile.unique_cards(), set); assert_eq!(pile.unique_cards().len(), 3); ``` -------------------------------- ### Constructing a Ganjifa deck Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/cards/ganjifa/fn.ganjifa_deck.html Demonstrates the usage of ganjifa_deck to create a deck with specific suits and strength parameters. ```rust use cardpack::prelude::*; const SLAVES_ONLY: [BasicCard; 12] = ganjifa_deck(&[MughalSuit::SLAVES], &[true]); assert_eq!(SLAVES_ONLY[0], GanjifaBasicCard::KING_SLAVES); ``` -------------------------------- ### Initialize and Manipulate a French Deck Source: https://docs.rs/cardpack Demonstrates creating a 54-card French deck, shuffling, parsing strings, and accessing card descriptions in multiple languages. ```rust // ignored under cargo test --no-default-features (uses fluent_name* / FluentName at the bottom) use cardpack::prelude::*; let mut french_deck = Pile::::deck(); // It's also possible to call the deck method directly on the specific generic implementing type: let mut french_deck = French::deck(); assert_eq!(french_deck.len(), 54); assert_eq!( french_deck.to_string(), "B🃟 L🃟 A♠ K♠ Q♠ J♠ T♠ 9♠ 8♠ 7♠ 6♠ 5♠ 4♠ 3♠ 2♠ A♥ K♥ Q♥ J♥ T♥ 9♥ 8♥ 7♥ 6♥ 5♥ 4♥ 3♥ 2♥ A♦ K♦ Q♦ J♦ T♦ 9♦ 8♦ 7♦ 6♦ 5♦ 4♦ 3♦ 2♦ A♣ K♣ Q♣ J♣ T♣ 9♣ 8♣ 7♣ 6♣ 5♣ 4♣ 3♣ 2♣" ); assert!(french_deck.contains(&Card::::new(FrenchBasicCard::ACE_SPADES))); let shuffled = french_deck.shuffled(); // Use the `french_cards!` macro to parse the shuffled deck as a string: let parsed = french_cards!(shuffled.to_string().as_str()); // Verify that the cards, in any order, are the same: assert!(french_deck.same(&parsed)); // When sorted, they should be exactly the same: assert_eq!(parsed.sorted(), french_deck); // For a joker card's index string, `B` stands for the Big or Full-Color Joker and `L` for the // Little or One-Color Joker, with `🃟` being the symbol character for the joker suit. let jokers = french_deck.draw(2).unwrap(); assert_eq!(jokers.to_string(), "B🃟 L🃟"); let royal_flush = french_deck.draw(5).unwrap(); assert_eq!(royal_flush.to_string(), "A♠ K♠ Q♠ J♠ T♠"); assert_eq!(royal_flush.index(), "AS KS QS JS TS"); // The original deck should now have five cards less: assert_eq!(french_deck.len(), 47); // Cards can provide a longer description in English and German: assert_eq!(Card::::new(FrenchBasicCard::ACE_SPADES).fluent_name_default(), "Ace of Spades"); assert_eq!(Card::::new(FrenchBasicCard::QUEEN_HEARTS).fluent_name(&FluentName::DEUTSCH), "Dame Herzen"); ``` -------------------------------- ### Generate a deck with deck() Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/traits/trait.Decked.html Demonstrates generating a deck using either a type parameter or a generic pile. ```rust use cardpack::prelude::*; // Each deck can be evoked in two ways: let deck_from_type_parameter: Pile = Pinochle::deck(); let deck_from_generic_pile = Pile::::deck(); assert_eq!(deck_from_type_parameter, deck_from_generic_pile); assert_eq!( deck_from_type_parameter.to_string(), "A♠ A♠ T♠ T♠ K♠ K♠ Q♠ Q♠ J♠ J♠ 9♠ 9♠ A♥ A♥ T♥ T♥ K♥ K♥ Q♥ Q♥ J♥ J♥ 9♥ 9♥ A♦ A♦ T♦ T♦ K♦ K♦ Q♦ Q♦ J♦ J♦ 9♦ 9♦ A♣ A♣ T♣ T♣ K♣ K♣ Q♣ Q♣ J♣ J♣ 9♣ 9♣" ); ``` -------------------------------- ### Standard Deck Usage in Rust Source: https://docs.rs/cardpack Demonstrates initializing a standard 52-card deck, shuffling, and dealing cards for a poker hand. ```rust use cardpack::prelude::*; fn main() { let mut pack = Standard52::deck(); pack.shuffle(); // Deal no-limit hold'em hands for two players: let small_blind = pack.draw(2).unwrap().sorted_by_rank(); let big_blind = pack.draw(2).unwrap().sorted_by_rank(); println!("small blind: {}", small_blind.to_string()); println!("big blind: {}", big_blind.to_string()); let flop = pack.draw(3).unwrap(); let turn = pack.draw(1).unwrap(); let river = pack.draw(1).unwrap(); println!(); println!("flop : {}", flop.to_string()); println!("turn : {}", turn.to_string()); println!("river: {}", river.to_string()); ``` -------------------------------- ### Retrieve Localized Suit Name Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Get the localized long name of the suit pip. ```rust use cardpack::prelude::*; let card = Card::::new(FrenchBasicCard::DEUCE_DIAMONDS); assert_eq!("Diamonds", card.fluent_suit_name(&FluentName::US_ENGLISH)); assert_eq!("Diamanten", card.fluent_suit_name(&FluentName::DEUTSCH)); ``` -------------------------------- ### Retrieve Localized Rank Name Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Get the localized long name of the rank pip. ```rust use cardpack::prelude::*; let card = Card::::new(FrenchBasicCard::DEUCE_DIAMONDS); assert_eq!("Deuce", card.fluent_rank_name(&FluentName::US_ENGLISH)); assert_eq!("Zwei", card.fluent_rank_name(&FluentName::DEUTSCH)); ``` -------------------------------- ### BasicCard::new Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_card/struct.BasicCard.html Constructs a new BasicCard instance from a suit and rank. ```APIDOC ## pub const fn new(suit: Pip, rank: Pip) -> Self ### Description Constructs a `BasicCard` from a suit and rank `Pip`. This method is `const`, allowing for the creation of `BasicCard` constants at compile time. ### Parameters - **suit** (Pip) - Required - The suit of the card. - **rank** (Pip) - Required - The rank of the card. ``` -------------------------------- ### CloneToUninit Implementation Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/dashavatara/struct.Dashavatara.html Experimental nightly-only API for performing copy-assignment to uninitialized memory. ```rust impl CloneToUninit for T where T: Clone, ``` ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Usage of FluentName::new Source: https://docs.rs/cardpack/0.9.0/cardpack/localization/struct.FluentName.html Demonstrates creating a FluentName instance and the default fallback behavior when an invalid name is provided. ```rust use cardpack::localization::*; assert_eq!("spades", FluentName::new("spades").fluent_name_string()); // Defaults to `BLANK` when an invalid name is passed in. assert_eq!( FluentName::BLANK, FluentName::new("+++").fluent_name_string() ); ``` -------------------------------- ### Displaying a BasicPile Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_pile/struct.BasicPile.html Demonstrates how to convert a BasicPile into a string representation using the Display trait. ```rust use cardpack::prelude::*; let hand = BasicPile::from( vec![ FrenchBasicCard::NINE_CLUBS, FrenchBasicCard::EIGHT_DIAMONDS, FrenchBasicCard::SEVEN_CLUBS, ] ); assert_eq!(hand.to_string(), "9♣ 8♦ 7♣"); ``` -------------------------------- ### Retrieve Localized Fluent Name Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Get the long name of the card based on a specific LanguageIdentifier. ```rust use cardpack::prelude::*; let card = Card::::new(FrenchBasicCard::NINE_CLUBS); assert_eq!("Nine of Clubs", card.fluent_name(&FluentName::US_ENGLISH)); assert_eq!("Neun Klee", card.fluent_name(&FluentName::DEUTSCH)); ``` -------------------------------- ### Pip::new Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pips/struct.Pip.html Constructs a new Pip instance. This is a const function, allowing for compile-time constant creation. ```APIDOC ## pub const fn new(pip_type: PipType, weight: usize, index: char, symbol: char) -> Self ### Description Constructs a `Pip`. The `value` field defaults to 0; use a struct literal or `Pip::update_value` for non-zero values. ### Parameters - **pip_type** (PipType) - The type of the pip. - **weight** (usize) - The weight of the pip. - **index** (char) - The index character. - **symbol** (char) - The symbol character. ``` -------------------------------- ### Retrieve Default Fluent Name Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Get the default US English long name of the card. ```rust use cardpack::prelude::*; let card = Card::::new(FrenchBasicCard::NINE_CLUBS); assert_eq!("Nine of Clubs", card.fluent_name_default()); ``` -------------------------------- ### basic! Source: https://docs.rs/cardpack/0.9.0/cardpack/macro.basic.html The basic macro takes a card string expression as an argument to perform its defined operation. ```APIDOC ## basic! ### Description A macro used to process a card string expression. ### Signature `macro_rules! basic { ($card_str:expr) => { ... }; }` ### Parameters - **$card_str** (expr) - Required - The card string expression to be processed by the macro. ``` -------------------------------- ### Compare Razz and Standard Decks Source: https://docs.rs/cardpack Illustrates the difference in card ordering between a Razz deck and a Standard52 deck. ```rust // ignored under cargo test --no-default-features (Razz needs the `yaml` feature) use cardpack::prelude::*; assert_eq!(Pile::::deck().draw(5).unwrap().to_string(), "A♠ 2♠ 3♠ 4♠ 5♠"); assert_eq!(Pile::::deck().draw(5).unwrap().to_string(), "A♠ K♠ Q♠ J♠ T♠"); ``` -------------------------------- ### Retrieve Card Color Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Get the color designated for a card's suit based on deck configuration. ```rust use cardpack::prelude::*; let card = Card::::new(FrenchBasicCard::TEN_DIAMONDS); assert_eq!(card.color(), Color::Red); ``` -------------------------------- ### ganjifa_deck Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/cards/ganjifa/index.html Builds a Ganjifa deck by generating courts and pips for each suit based on the specified ladder strength. ```APIDOC ## Function: ganjifa_deck ### Description Builds a Ganjifa deck: for each suit, courts + 10 pips from the strong or weak ladder, in descending-weight (sorted) order. ``` -------------------------------- ### Deck Generation Methods Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Methods for creating and managing decks. ```APIDOC ## deck() ### Description Generates a new deck of cards based on the specific type parameters. ## decks(count: usize) ### Description Creates a specified number of decks in a single Pile. ``` -------------------------------- ### Define basic macro Source: https://docs.rs/cardpack/0.9.0/cardpack/macro.basic.html The basic macro definition using macro_rules! syntax. ```rust macro_rules! basic { ($card_str:expr) => { ... }; } ``` -------------------------------- ### macro_rules! basic Source: https://docs.rs/cardpack/0.9.0/cardpack/prelude/macro.basic.html The basic macro takes a card string expression as an argument to initialize or process card data. ```APIDOC ## macro_rules! basic ### Description A macro used to parse or initialize card structures from a string expression. ### Signature macro_rules! basic { ($card_str:expr) => { ... }; } ``` -------------------------------- ### Compiler Error Hint for Trait Implementation Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Example of a compiler error encountered when calling an associated function on a trait without specifying the implementation type. ```text error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> src/basic/types/bcard:151:9 | 151 | DeckedBase::basic_pile().contains(&self.base_card) | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait | ::: src/basic/types/traits.rs:17:5 | 17 | / fn basic_pile() -> BasicPile { 18 | | BasicPile::from(Self::base_vec()) 19 | | } | |_____- `DeckedBase::basic_pile` defined here | help: use a fully-qualified path to one of the available implementations | 151 | ::basic_pile().contains(&self.base_card) | +++++++++++ + 151 | ::basic_pile().contains(&self.base_card) | ++++++++++++ + 151 | ::basic_pile().contains(&self.base_card) | ++++++++++++ + 151 | ::basic_pile().contains(&self.base_card) | ++++++++++ + and 10 other candidates ``` -------------------------------- ### cards! Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html A macro to create a Pile of Standard52 cards from a string. ```APIDOC ## cards! ### Description This macro creates a `Pile` of `Standard52` cards based on a provided string representation. ### Usage Pass a string representing the desired cards to generate a collection (Pile) of Standard52 cards. ``` -------------------------------- ### Sort Pile by Default Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/mughal/type.MughalDeck.html Demonstrates creating a sorted clone of a pile and sorting a pile in place. ```rust use cardpack::prelude::*; let deck = Euchre32::deck(); let shuffled = deck.shuffled(); assert!(deck.same(&shuffled)); assert_eq!(deck, shuffled.sorted()); ``` ```rust use cardpack::prelude::*; ``` -------------------------------- ### to_fg_str Source: https://docs.rs/cardpack/0.9.0/cardpack/prelude/enum.Color.html Converts the color to its foreground string representation. ```APIDOC ## pub fn to_fg_str(&self) -> Cow<'static, str> ### Description Returns the foreground string representation of the color. ``` -------------------------------- ### card! Source: https://docs.rs/cardpack/0.9.0/cardpack/index.html A macro to allow for quick and easy generation of individual cards from the most common Standard52 deck. ```APIDOC ## card! ### Description This macro allows for the quick and easy generation of individual cards from the most common `Standard52` deck. ### Usage Use this macro to instantiate a single card object within your Rust code. ``` -------------------------------- ### basic_cell!($card_str:expr) Source: https://docs.rs/cardpack/0.9.0/cardpack/prelude/macro.basic_cell.html A macro that takes a string expression and initializes a cell. This is part of the cardpack::prelude module. ```APIDOC ## basic_cell!($card_str:expr) ### Description Initializes a cell structure using the provided string expression. ### Syntax `basic_cell!($card_str:expr)` ### Parameters - **$card_str** (expr) - Required - A string expression representing the card data to be converted into a cell. ``` -------------------------------- ### Configure cardpack dependencies Source: https://docs.rs/cardpack Specify the cardpack version and enabled features in your Cargo.toml file. ```toml cardpack = { version = "0.8", features = ["full"] } ``` ```toml cardpack = { version = "0.8", features = ["serde"] } ``` ```toml cardpack = "0.8" ``` -------------------------------- ### to_bg_str Source: https://docs.rs/cardpack/0.9.0/cardpack/prelude/enum.Color.html Converts the color to its background string representation. ```APIDOC ## pub fn to_bg_str(&self) -> Cow<'static, str> ### Description Returns the background string representation of the color. ``` -------------------------------- ### Parse FluentName from String Source: https://docs.rs/cardpack/0.9.0/cardpack/localization/struct.FluentName.html Demonstrates converting a string into a FluentName instance using FromStr, including handling of valid and invalid inputs. ```rust use std::str::FromStr; use cardpack::localization::*; assert_eq!( "hierophant", FluentName::from_str("hierophant").unwrap().fluent_name_string() ); ``` ```rust use std::str::FromStr; use cardpack::common::errors::CardError; use cardpack::localization::*; let sut = FluentName::from_str("Only alphanumeric and hyphens please."); assert_eq!( CardError::InvalidFluentName("Only alphanumeric and hyphens please.".to_string()), sut.unwrap_err() ); ``` -------------------------------- ### french_cards! Source: https://docs.rs/cardpack/0.9.0/cardpack/macro.french_cards.html A macro to create a Pile of French Deck cards from a string. If the passed in string isn’t valid, it will simply return an empty pile. ```APIDOC ## french_cards! ### Description A macro to create a Pile of `French Deck` cards from a string. If the passed in string isn’t valid, it will simply return an empty pile. ### Signature `macro_rules! french_cards { ($card_str:expr) => { ... }; }` ### Parameters - **$card_str** (expr) - Required - A string expression representing the French deck cards to be created. ``` -------------------------------- ### Borrow and BorrowMut Implementations Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/dashavatara/struct.Dashavatara.html Standard library blanket implementations for borrowing and mutably borrowing owned values. ```rust impl Borrow for T where T: ?Sized, ``` ```rust fn borrow(&self) -> &T ``` ```rust impl BorrowMut for T where T: ?Sized, ``` ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### FromStr Trait Implementation for Card Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/canasta/type.CanastaCard.html Shows how to create a Card from various string representations, including support for case-insensitive indexes and symbols. ```rust use cardpack::prelude::*; let card = Card::::new(FrenchBasicCard::ACE_SPADES); let possible = vec!["AS", "as", "aS", "As", "A♠", "a♠"]; for s in possible { assert_eq!(card, Card::::from_str(s).unwrap()); } ``` -------------------------------- ### Definition of TO_DO_LIST constant Source: https://docs.rs/cardpack/0.9.0/cardpack/funky/decks/joker/card/constant.TO_DO_LIST.html Displays the signature of the TO_DO_LIST constant. ```rust pub const TO_DO_LIST: BuffoonCard; ``` -------------------------------- ### String Formatting Methods Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/euchre32/type.Euchre32Deck.html Methods for converting piles to formatted strings. ```APIDOC ## stringify(s: &str, f: fn(&Card) -> String) ### Description Returns a String of the Pile with the passed in function applied to each Card, joined by the provided separator. ## to_color_index_string() ### Description Returns a color-formatted version of the index string of the Pile. ## to_color_symbol_string() ### Description Returns a color-formatted version of the symbol string of the Pile. ``` -------------------------------- ### Iterate over all shipped decks Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/registry/index.html Use DeckKind::all() to retrieve a list of all decks shipped with the crate and access their metadata. ```rust use cardpack::prelude::*; // Every deck cardpack ships, in a stable order: for kind in DeckKind::all() { println!("{} has {} cards", kind.deck_name(), kind.base_vec().len()); } ``` -------------------------------- ### Retrieve Fluent Values Source: https://docs.rs/cardpack/0.9.0/cardpack/localization/trait.Named.html Demonstrates fetching a specific localized value using a key and language identifier. ```rust use cardpack::localization::*; assert_eq!( "♠", FluentName::new("spades").fluent_value("symbol", &FluentName::US_ENGLISH) ); ``` -------------------------------- ### From and Into Conversions Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/dashavatara/struct.Dashavatara.html Standard conversion traits for transforming types. ```rust impl From for T ``` ```rust fn from(t: T) -> T ``` ```rust impl Into for T where U: From, ``` ```rust fn into(self) -> U ``` -------------------------------- ### Check for blank Pip Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pips/struct.Pip.html Verify if a card is blank using the default Pip configuration. ```rust use cardpack::prelude::*; assert!(Card::::default().is_blank()); ``` -------------------------------- ### Sort BasicPile into a new instance Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_pile/struct.BasicPile.html Creates a new sorted BasicPile from an existing one. ```rust use cardpack::prelude::*; assert_eq!(basic!("2♠ A♣ 3♠ 4♠ 5♣").sorted().to_string(), "4♠ 3♠ 2♠ A♣ 5♣"); ``` -------------------------------- ### Create multiple decks with decks() Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/traits/trait.Decked.html Creates a pile containing multiple instances of a specific deck type. ```rust use cardpack::prelude::*; let twodecks = Pile::::decks(2); assert_eq!(twodecks.len(), 104); // Converting it to a `BTreeSet` will verify that there are only 52 unique cards. assert_eq!(twodecks.unique_cards().len(), 52); ``` ```rust fn decks(n: usize) -> Pile { Pile::::pile_up(n, >::deck) } ``` -------------------------------- ### BuffoonCard Copy Implementation Source: https://docs.rs/cardpack/0.9.0/cardpack/funky/types/buffoon_card/struct.BuffoonCard.html Demonstrates the preferred fluid style for returning a modified copy of a BuffoonCard. ```rust BuffoonCard { suit: self.suit, rank, card_type: self.card_type, enhancement: self.enhancement, } ``` -------------------------------- ### basic_buffoon_pile Source: https://docs.rs/cardpack/0.9.0/cardpack/funky/decks/basic/struct.Deck.html Returns a new BuffoonPile instance based on the basic deck configuration. ```APIDOC ## fn basic_buffoon_pile() ### Description Creates and returns a new `BuffoonPile` instance, representing the basic deck configuration. ### Signature `pub fn basic_buffoon_pile() -> BuffoonPile` ``` -------------------------------- ### Create a Pile from a string Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pile/struct.Pile.html Initialize a Pile of cards using a string representation. ```rust use cardpack::prelude::*; let hand: Pile = Pile::::from_str("AD KD QD JD TD").unwrap(); assert_eq!(hand.len(), 5); assert_eq!(hand.to_string(), "A♦ K♦ Q♦ J♦ T♦"); ``` -------------------------------- ### pub fn stringify(&self, s: &str, f: fn(&Card) -> String) -> String Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/mughal/type.MughalDeck.html Returns a String of the Pile with the passed in function applied to each Card. ```APIDOC ## pub fn stringify(&self, s: &str, f: fn(&Card) -> String) -> String ### Description Returns a String of the `Pile` with the passed in function applied to each `Card`. ``` -------------------------------- ### Construct a Pip constant Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/pips/struct.Pip.html Create a new Pip at compile time using the const constructor. ```rust use cardpack::prelude::*; pub const ACE: Pip = Pip::new(PipType::Rank, 12, 'A', 'A'); assert_eq!(ACE.weight, 12); assert_eq!(ACE.value, 0); ``` -------------------------------- ### Retrieve Index Strings for a Deck Source: https://docs.rs/cardpack Displays how to retrieve the index string representation of a deck, which uses letters instead of suit symbols. ```rust use cardpack::prelude::*; assert_eq!( Pile::::deck().index(), "AS KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AH KH QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AD KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AC KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C" ); ``` -------------------------------- ### pub fn sort(&mut self) Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/mughal/type.MughalDeck.html Sorts the Pile in place. ```APIDOC ## pub fn sort(&mut self) ### Description Sorts the `Pile` in place. ``` -------------------------------- ### Create a Custom Deck in Rust Source: https://docs.rs/cardpack Defines a custom deck structure by implementing the DeckedBase trait and providing a macro for card instantiation. ```rust // ignored under cargo test --no-default-features (uses colored::Color directly) use std::collections::HashMap; use colored::Color; use cardpack::prelude::*; #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Tiny {} impl Tiny { pub const DECK_SIZE: usize = 4; pub const DECK: [BasicCard; Tiny::DECK_SIZE] = [ FrenchBasicCard::ACE_SPADES, FrenchBasicCard::KING_SPADES, FrenchBasicCard::ACE_HEARTS, FrenchBasicCard::KING_HEARTS, ]; } impl DeckedBase for Tiny { fn base_vec() -> Vec { Tiny::DECK.to_vec() } fn colors() -> HashMap { Standard52::colors() } fn deck_name() -> String { "Tiny".to_string() } fn fluent_deck_key() -> String { FLUENT_KEY_BASE_NAME_FRENCH.to_string() } } // Let's you call Decked methods directly on the Tiny type: impl Decked for Tiny {} macro_rules! tiny { (AS) => { Card::::new(FrenchBasicCard::ACE_SPADES) }; (KS) => { Card::::new(FrenchBasicCard::KING_SPADES) }; (AH) => { Card::::new(FrenchBasicCard::ACE_HEARTS) }; (KH) => { Card::::new(FrenchBasicCard::KING_HEARTS) }; (__) => { Card::::default() }; } let mut deck = Tiny::deck(); assert_eq!(deck.to_string(), "A♠ K♠ A♥ K♥"); // Every deck comes with the Ranged trait automatically: assert_eq!(deck.combos(2).to_string(), "A♠ K♠, A♠ A♥, A♠ K♥, K♠ K♥, A♥ K♠, A♥ K♥"); // Deal from the top of the deck: assert_eq!(deck.draw_first().unwrap().to_string(), "A♠"); // Deal from the bottom of the deck: assert_eq!(deck.draw_last().unwrap().to_string(), "K♥"); // Should be two cards remaining: assert_eq!(deck.len(), 2); assert_eq!(deck.index(), "KS AH"); // Draw a remaining card: assert_eq!(deck.draw_first().unwrap(), tiny!(KS)); // Draw the last card: assert_eq!(deck.draw_last().unwrap(), tiny!(AH)); // And now the deck is empty: assert!(deck.draw_first().is_none()); assert!(deck.draw_last().is_none()); // Of all the tests you could use to make sure that your deck is setup correctly, the most // fundamental is the validate method. assert!(Tiny::validate()); ``` -------------------------------- ### Retrieve Connectors Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/combos/struct.Combos.html Returns every possible combination of cards of a given length for a specific BasicPile. ```rust use cardpack::prelude::*; use cardpack::basic::decks::tiny::Tiny; let pile: BasicPile = (&Pile::::deck()).into(); let combos = pile.combos(2).connectors(); assert_eq!(combos.len(), 4); assert_eq!( combos.to_string(), "A♠ K♠, A♠ K♥, A♥ K♠, A♥ K♥" ); ``` -------------------------------- ### pub fn to_color_index_string(&self) -> String Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/mughal/type.MughalDeck.html Returns a Color version of the index string of the Pile. ```APIDOC ## pub fn to_color_index_string(&self) -> String ### Description Returns a Color version of the index string of the `Pile`. ``` -------------------------------- ### pub fn to_color_symbol_string(&self) -> String Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/mughal/type.MughalDeck.html Returns a Color version of the symbol string of the Pile. ```APIDOC ## pub fn to_color_symbol_string(&self) -> String ### Description Returns a Color version of the symbol string of the `Pile`. ``` -------------------------------- ### Draw cards from a BasicPile Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_pile/struct.BasicPile.html Demonstrates drawing a specific number of cards from a pile and verifying the result. ```rust use cardpack::prelude::*; let mut pile = Pinochle::deck().into_basic_pile(); let hand = pile.draw(5).unwrap(); assert_eq!(hand.to_string(), "A♠ A♠ T♠ T♠ K♠"); ``` -------------------------------- ### Load BasicCards from a YAML file Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_card/struct.BasicCard.html Read card data from a YAML file. Requires the std-io feature to be enabled. ```rust use cardpack::prelude::*; let cards = BasicCard::cards_from_yaml_file("src/basic/decks/yaml/french.yaml").unwrap(); assert_eq!(cards.len(), 54); assert_eq!(cards, Pile::::base_vec()); ``` -------------------------------- ### Define SHORTCUT constant Source: https://docs.rs/cardpack/0.9.0/cardpack/funky/decks/joker/card/constant.SHORTCUT.html Represents the SHORTCUT constant definition as a BuffoonCard. ```rust pub const SHORTCUT: BuffoonCard; ``` -------------------------------- ### Define FLUENT_KEY_BASE_NAME_PINOCHLE Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/cards/pinochle/constant.FLUENT_KEY_BASE_NAME_PINOCHLE.html Constant representing the base string key for Pinochle localization. ```rust pub const FLUENT_KEY_BASE_NAME_PINOCHLE: &str = "pinochle"; ``` -------------------------------- ### Sort BasicPile by rank into a new instance Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/types/basic_pile/struct.BasicPile.html Creates a new BasicPile sorted specifically by card rank. ```rust use cardpack::prelude::*; assert_eq!(basic!("2♠ A♣ 3♠ 4♠ 5♣").sorted_by_rank().to_string(), "A♣ 5♣ 4♠ 3♠ 2♠"); ``` -------------------------------- ### From Trait Implementation Source: https://docs.rs/cardpack/0.9.0/cardpack/basic/decks/french/struct.French.html Returns the argument unchanged. ```rust impl From for T ``` ```rust fn from(t: T) -> T ``` -------------------------------- ### Accessing the LOYALTY_CARD constant Source: https://docs.rs/cardpack/0.9.0/cardpack/funky/decks/joker/card/constant.LOYALTY_CARD.html Displays the type definition for the LOYALTY_CARD constant. ```rust pub const LOYALTY_CARD: BuffoonCard; ```