rust_cards

Crates.iorust_cards
lib.rsrust_cards
version0.1.2
sourcesrc
created_at2021-07-19 05:42:26.176779
updated_at2021-07-20 06:11:15.760696
descriptionSimulates playing cards
homepage
repositoryhttps://github.com/ottobrown/rust_cards
max_upload_size
id424595
size13,322
(ottobrown)

documentation

README

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

Commit count: 0

cargo fmt