Skip to main content

Module hand

Module hand 

Source
Expand description

Card primitives: ranks, cards, holdings, and hands.

Rank is a non-zero byte in 2..=14 (J/Q/K/A as 11/12/13/14). Card pairs a Rank with a Suit and packs into a single byte. Holding is a 13-bit bitset of ranks within one suit, and Hand is four holdings packed into a u64. Set operations on holdings and hands are exposed through the standard bitwise operators.

Iteration yields cards in descending suit order (spades first) and descending rank order within each suit, matching the conventional display order.

§Panic policy

Rank::new panics when the input is outside 2..=14 and has Rank::try_new for fallible construction. In const contexts the panic becomes a compile-time error.

Structs§

Card
A playing card
Hand
A hand of playing cards
HandIter
Iterator over the cards in a Hand, yielding Cards in descending suit order and descending rank order within each suit
Holding
A set of cards of the same suit
HoldingIter
Iterator over the ranks in a Holding, yielding Ranks in descending order
InvalidRank
Error indicating an invalid rank
ParseRankError
Error returned when parsing a Rank fails
Rank
The rank of a card, from 2 to 14, where J, Q, K, A are internally denoted as 11, 12, 13, 14 respectively.

Enums§

ParseCardError
Error returned when parsing a Card fails
ParseHandError
An error which can be returned when parsing a Hand
ParseHoldingError
An error which can be returned when parsing a Holding