rust_cards 0.1.2

Simulates playing cards
Documentation
  • Coverage
  • 25.53%
    12 out of 47 items documented5 out of 24 items with examples
  • Size
  • Source code size: 16.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.54 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ottobrown

rust-cards


A simple library for simulating playing cards

Structure

A Card is a struct with 2 fields, elements of the enums Suit and Value. A Hand is a struct consisting of a Vec of Card

Suit ----↓
        Card ----→ [Card Card Card Card Card] --→ Hand
Value ---↑

Examples

Creates a deck, shuffles it, and pops the top 5 cards onto a Hand

use rust_cards::cards::Card;
use rust_cards::hand::Hand;


fn main() {
    let mut deck = Hand::full_deck();
    deck = deck.shuffle();

    //pops the top 5 cards off the deck and puts them in a hand 
    let top_five_cards = Hand::from(
        vec![
            deck.pop_top(),
            deck.pop_top(),
            deck.pop_top(),
            deck.pop_top(),
            deck.pop_top(),
        ]
    );

    for card in top_five_cards.vec {
        println!("{}", card.string())
    }

}

creates a hand consinsting of A♠, 2♥, 3♦, 4♣

use rust_cards::cards::Card;
use rust_cards::hand::Hand;
use rust_cards::cards::Suit;
use rust_cards::cards::Value;

fn main() {
    let set_hand = Hand::from(
        vec![
            Card::new(Value::Ace, Suit::Spade),
            Card::new(Value::Two, Suit::Heart),
            Card::new(Value::Three, Suit::Diamond),
            Card::new(Value::Four, Suit::Club)
        ]
    );

    for card in set_hand.vec {
        println!("{}", card.string())
    }
    //A♠
    //2♥
    //3♦
    //4♣
}

##License MIT or Apache-2.0