Skip to content

Instantly share code, notes, and snippets.

@dradtke
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save dradtke/627801ca5da80aa5ab4c to your computer and use it in GitHub Desktop.

Select an option

Save dradtke/627801ca5da80aa5ab4c to your computer and use it in GitHub Desktop.
Rustic deck of cards.
use std::rand::{task_rng, Rng};
#[allow(dead_code)]
enum Value {
Ace,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
}
#[allow(dead_code)]
enum Suit {
Clubs,
Diamonds,
Hearts,
Spades,
}
type Card = (Value, Suit);
type Deck = Vec<Card>;
fn new_deck() -> Deck {
vec![
(Ace, Clubs),
(Two, Clubs),
// everything else here
]
}
fn shuffle_deck(deck: &mut Deck) {
task_rng().shuffle(deck.as_mut_slice());
}
fn main() {
let mut deck = new_deck();
shuffle_deck(&mut deck);
// use the deck here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment