Struct card_deck::deck::Deck[][src]

pub struct Deck<C> { /* fields omitted */ }

A Deck of cards

Methods

impl<C> Deck<C>
[src]

Builds a deck using the supplied cards and defaults for all other options

Creates a Builder for the Deck, see DeckBuilder

Add a card to the discard pile

Adds the Discard Pile to the bottom of the draw pile, shuffling if shuffle_discards

use card_deck::Deck;
let mut dk = Deck::build()
            .draw_pile(vec![1,2,3])
            .discard_pile(vec![4])
            .stop_on_discards(true).done();

assert_eq!(dk.len(),3);
assert_eq!(dk.discard_len(),1);
dk.discards_to_bottom();
assert_eq!(dk.len(),4);
assert_eq!(dk.discard_len(),0);

assert_eq!(dk.draw_all().last(),Some(4));

Returns None if nothing to draw

returns the maximum number of cards that can be drawn in a single draw

Currently slow, as for each found element has to do slow remove, When drain_filter is off nightly will be fixed to use that. Dont rely on this returning an IntoIter, but expect an Iterator of some form

Trait Implementations

impl<C: Debug> Debug for Deck<C>
[src]

Formats the value using the given formatter. Read more

impl<C: Clone> Clone for Deck<C>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a, C> IntoIterator for &'a Deck<C>
[src]

Peeking cards

use card_deck::Deck;
let dk = Deck::build().draw_pile(vec![1,2,3]).discard_pile(vec![4]).done();
let mut n = 0;
for c in &dk{
    n += c;
}
assert_eq!(n,10);

//with stop_on_discards

let dk = Deck::build().draw_pile(vec![1,2,3]).discard_pile(vec![4])
                .stop_on_discards(true).done();
let mut n = 0;
for c in &dk{
    n += c;
}
assert_eq!(n,6);
 

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, C> IntoIterator for &'a mut Deck<C>
[src]

Tweaking cards

use card_deck::Deck;
let mut dk = Deck::build().draw_pile(vec![1,2,3]).pre_shuffle(false).done();
{
    for c in &mut dk{
      *c = *c +1;
    }
}

assert_eq!(dk.draw_1(),Some(2));

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<C> Send for Deck<C> where
    C: Send

impl<C> Sync for Deck<C> where
    C: Sync