1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use deck::{Deck};

use std::iter::{Iterator};

///Provide iterator impl for decks.
///It does this by removing cards from the top of the deck
#[derive(Debug)]
pub struct DeckIterator<'a, C, T: 'a + Deck<Card=C>> {
    _deck: &'a mut T
}

impl<'a, C, T: Deck<Card=C>> DeckIterator<'a, C, T> {
    pub fn new(deck :&'a mut T) -> DeckIterator<'a, C, T>
    {
    	DeckIterator{_deck: deck}
    }
}

impl<'a, C, T: Deck<Card=C>> Iterator for DeckIterator<'a, C, T>
{
	type Item=C;
	fn next(&mut self) -> Option<Self::Item>
	{
		self._deck.remove_card_from_top()
	}
}