Struct rust_cards::hand::Hand[][src]

pub struct Hand {
    pub vec: Vec<Card>,
}

Fields

vec: Vec<Card>

Implementations

returns a hand from a Vec of Card

returns a Hand containing a full deck

ordered 2, 3, 4, … J, Q, K, A Suits ordered Club(♣), Diamond(♦), Heart(♥), Spade(♠)

Randomizes the order of the hand

returns a new value; does not mutate the original value

reverses the hand i.e. the first index becomes the last index, the second index becomes the second-last index, etc.Hand

returns a new value; does not mutate the original value

removes the first indexed card in the hand and returns its value

mutates the hand; doesn’t return a new hand

let mut h = Hand::from(
    vec![
        Card::new(Value::Ace, Suit::Spade)
        Card::new(Value::Two, Suit::Spade)
        Card::new(Value::Three, Suit::Spade)
    ]
);
// A♠, 2♠, 3♠
 
let popped = h.pop();
// h == 2♠, 3♠
// popped == A♠

removes the last indexed card in the hand and returns its value

mutates the hand; doesn’t return a new hand

let mut h = Hand::from(
    vec![
        Card::new(Value::Ace, Suit::Spade)
        Card::new(Value::Two, Suit::Spade)
        Card::new(Value::Three, Suit::Spade)
    ]
);
// A♠, 2♠, 3♠
 
let popped = h.pop();
// h == A♠, 2♠
// popped == 3♠

Pushes a card to the top of the hand

let mut h = Hand::from(
    vec![
        Card::new(Value::Ace, Suit::Spade)
        Card::new(Value::Two, Suit::Spade)
        Card::new(Value::Three, Suit::Spade)
    ]
);
// A♠, 2♠, 3♠
 
h = h.push(Card::new(Value::King, Suit::Spade))
// K♠, A♠, 2♠, 3♠

Pushes a card to the bottom of the hand

let mut h = Hand::from(
    vec![
        Card::new(Value::Ace, Suit::Spade)
        Card::new(Value::Two, Suit::Spade)
        Card::new(Value::Three, Suit::Spade)
    ]
);
// A♠, 2♠, 3♠
 
h = h.push(Card::new(Value::Four, Suit::Spade))
// A♠, 2♠, 3♠, 4♠

Stacks a hand on top of another Hand

 

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.