pub struct Hand(/* private fields */);Expand description
A set of playing cards
Despite the name, this type is a general card set: it also represents melds, deadwood, and the union of several hands throughout this crate.
Implementations§
Source§impl Hand
impl Hand
Sourcepub const fn to_bits(self) -> u64
pub const fn to_bits(self) -> u64
As a bitset of cards
The card of suit s and rank r is bit 16 × s + r, i.e. each suit
owns a 16-bit lane in ascending suit order and a lane is the
Holding::to_bits of that suit. This layout is a stable API
contract of this crate.
Sourcepub const fn from_bits_retain(bits: u64) -> Self
pub const fn from_bits_retain(bits: u64) -> Self
Create a hand from a bitset of cards, retaining invalid cards
Sourcepub const fn contains_unknown_bits(self) -> bool
pub const fn contains_unknown_bits(self) -> bool
Whether the hand contains an invalid card
Sourcepub const fn from_bits(bits: u64) -> Option<Self>
pub const fn from_bits(bits: u64) -> Option<Self>
Create a hand from a bitset of cards, checking for invalid cards
Sourcepub const fn from_bits_truncate(bits: u64) -> Self
pub const fn from_bits_truncate(bits: u64) -> Self
Create a hand from a bitset of cards, removing invalid cards
Sourcepub const fn new(
clubs: Holding,
diamonds: Holding,
hearts: Holding,
spades: Holding,
) -> Self
pub const fn new( clubs: Holding, diamonds: Holding, hearts: Holding, spades: Holding, ) -> Self
Create a hand from four holdings in suit order (clubs, diamonds, hearts, spades)
Sourcepub fn insert(&mut self, card: Card) -> bool
pub fn insert(&mut self, card: Card) -> bool
Insert a card into the hand, returning whether it was newly inserted
Sourcepub fn remove(&mut self, card: Card) -> bool
pub fn remove(&mut self, card: Card) -> bool
Remove a card from the hand, returning whether it was present
Sourcepub fn toggle(&mut self, card: Card) -> bool
pub fn toggle(&mut self, card: Card) -> bool
Toggle a card in the hand, returning whether it is now present
Trait Implementations§
Source§impl BitAndAssign for Hand
impl BitAndAssign for Hand
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOrAssign for Hand
impl BitOrAssign for Hand
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXorAssign for Hand
impl BitXorAssign for Hand
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreimpl Copy for Hand
Source§impl<'de> Deserialize<'de> for Hand
impl<'de> Deserialize<'de> for Hand
Source§fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Hand
Dotted display of a hand: four suit groups in ascending order, clubs
first, e.g. A23.456.789.T
impl Display for Hand
Dotted display of a hand: four suit groups in ascending order, clubs
first, e.g. A23.456.789.T
An empty hand is shown as -. Note that this deliberately differs from
the descending, spades-first PBN format of bridge software.
This implementation ignores formatting flags for simplicity and speed.