pub struct Card(/* private fields */);Expand description
A Card is a Newtype
u32 representation of a variant of Cactus Kev’s binary representation of a poker card as
designed for rapid hand evaluation as documented here.
The variation being that the Suit bits order is inverted for easier sorting.
+--------+--------+--------+--------+
|mmmbbbbb|bbbbbbbb|SHDCrrrr|xxpppppp|
+--------+--------+--------+--------+
p = prime number of rank (deuce=2,trey=3,four=5,...,ace=41)
r = rank of card (deuce=0,trey=1,four=2,five=3,...,ace=12)
SHDC = suit of card (bit turned on based on suit of card)
b = bit turned on depending on rank of card
m = Flags reserved for multiples of the same rank. Stripped for evals.Implementations§
Source§impl Card
impl Card
pub const RANK_FLAG_FILTER: u32 = 0x1FFF_0000
pub const RANK_FLAG_SHIFT: u32 = 16
pub const RANK_PRIME_FILTER: u32 = 0b0011_1111
Sourcepub const SUIT_FLAG_FILTER: u32 = 0xF000
pub const SUIT_FLAG_FILTER: u32 = 0xF000
Binary filter for CardNumber Suit flags.
00000000 00000000 11110000 00000000
pub const SUIT_SHORT_MASK: u32 = 0b1111
pub const SUIT_FLAG_SHIFT: u32 = 12
Sourcepub const FREQUENCY_PAIRED_MASK: u32 = 0b0010_0000_0000_0000_0000_0000_0000_0000
pub const FREQUENCY_PAIRED_MASK: u32 = 0b0010_0000_0000_0000_0000_0000_0000_0000
Frequency Weight masks
pub const FREQUENCY_TRIPPED_MASK: u32 = 0b0100_0000_0000_0000_0000_0000_0000_0000
pub const FREQUENCY_QUADED_MASK: u32 = 0b1000_0000_0000_0000_0000_0000_0000_0000
pub const FREQUENCY_MASK: u32 = 0b1110_0000_0000_0000_0000_0000_0000_0000
pub const FREQUENCY_MASK_FILTER: u32 = 0b0001_1111_1111_1111_1111_1111_1111_1111
pub const ACE_SPADES: Card
pub const KING_SPADES: Card
pub const QUEEN_SPADES: Card
pub const JACK_SPADES: Card
pub const TEN_SPADES: Card
pub const NINE_SPADES: Card
pub const EIGHT_SPADES: Card
pub const SEVEN_SPADES: Card
pub const SIX_SPADES: Card
pub const FIVE_SPADES: Card
pub const FOUR_SPADES: Card
pub const TREY_SPADES: Card
pub const DEUCE_SPADES: Card
pub const ACE_HEARTS: Card
pub const KING_HEARTS: Card
pub const QUEEN_HEARTS: Card
pub const JACK_HEARTS: Card
pub const TEN_HEARTS: Card
pub const NINE_HEARTS: Card
pub const EIGHT_HEARTS: Card
pub const SEVEN_HEARTS: Card
pub const SIX_HEARTS: Card
pub const FIVE_HEARTS: Card
pub const FOUR_HEARTS: Card
pub const TREY_HEARTS: Card
pub const DEUCE_HEARTS: Card
pub const ACE_DIAMONDS: Card
pub const KING_DIAMONDS: Card
pub const QUEEN_DIAMONDS: Card
pub const JACK_DIAMONDS: Card
pub const TEN_DIAMONDS: Card
pub const NINE_DIAMONDS: Card
pub const EIGHT_DIAMONDS: Card
pub const SEVEN_DIAMONDS: Card
pub const SIX_DIAMONDS: Card
pub const FIVE_DIAMONDS: Card
pub const FOUR_DIAMONDS: Card
pub const TREY_DIAMONDS: Card
pub const DEUCE_DIAMONDS: Card
pub const ACE_CLUBS: Card
pub const KING_CLUBS: Card
pub const QUEEN_CLUBS: Card
pub const JACK_CLUBS: Card
pub const TEN_CLUBS: Card
pub const NINE_CLUBS: Card
pub const EIGHT_CLUBS: Card
pub const SEVEN_CLUBS: Card
pub const SIX_CLUBS: Card
pub const FIVE_CLUBS: Card
pub const FOUR_CLUBS: Card
pub const TREY_CLUBS: Card
pub const DEUCE_CLUBS: Card
pub const BLANK: Card
pub fn new(rank: Rank, suit: Suit) -> Self
Sourcepub fn filter(card: Card) -> Result<Self, PKError>
pub fn filter(card: Card) -> Result<Self, PKError>
§Errors
Returns PKError::BlankCard if the Card is blank.
pub fn bit_string(&self) -> String
Sourcepub fn bit_string_guided(&self) -> String
pub fn bit_string_guided(&self) -> String
This code is doing too much. I need to Uncle Bob it. Aside on why I am giving up that phrase.
Sourcepub fn frequency_paired(&self) -> Card
pub fn frequency_paired(&self) -> Card
Returns a new version of Card with the paired frequency bit set.
Sourcepub fn frequency_tripped(&self) -> Card
pub fn frequency_tripped(&self) -> Card
Returns a new version of Card with the tripped frequency bit set.
Sourcepub fn frequency_quaded(&self) -> Card
pub fn frequency_quaded(&self) -> Card
Returns a new version of Card with the quaded frequency bit set.
Quaded??!!
pub fn get_letter_index(&self) -> String
pub fn get_rank(&self) -> Rank
pub fn get_rank_prime(&self) -> u32
pub fn get_suit(&self) -> Suit
pub fn is_flagged(&self, flag: u32) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Card
impl<'de> Deserialize<'de> for Card
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 From<&Card> for Cards
impl From<&Card> for Cards
Source§fn from(card: &Card) -> Self
fn from(card: &Card) -> Self
Turns out we already have a TryFrom<Card> implemented, but I want something similar.
This will give us the contract that if it’s blank it won’t be inserted, which is fine.
I can see wanted to do both versions of the functionality.
When I am coding in rust, I do feel the constant tension between my desire to make things just flow as easily as possible in the short term, and wanting to code things the right, “rusty” way.
My general rule is to follow Socrates’ maxim: the unexamined life is not worth living. Know why you are doing anything. Following rules blindly makes you a tool. If you can’t answer questions like: why did you code it this way? and what’s the purpose of this test? you need to take a step back
Source§impl FromIterator<Card> for Cards
impl FromIterator<Card> for Cards
Source§impl Ord for Card
impl Ord for Card
Source§impl PartialOrd for Card
impl PartialOrd for Card
Source§impl Pile for Card
impl Pile for Card
fn add<P: Pile>(&self, _other: P) -> Selfwhere
Self: Sized,
fn card_at(self, _index: usize) -> Option<Card>
Source§fn clean(&self) -> Self
fn clean(&self) -> Self
fn contains_blank(&self) -> bool
fn swap(&mut self, _index: usize, card: Card) -> Option<Card>
fn the_nuts(&self) -> TheNuts
fn to_vec(&self) -> Vec<Card>
Source§fn are_unique(&self) -> bool
fn are_unique(&self) -> bool
oli_obk.fn bard(&self) -> Bard
fn cards(&self) -> Cards
Source§fn collapse(&self) -> u32
fn collapse(&self) -> u32
This is a bit of a hack. I’m not sure if I should be doing this. I’m going to try it andRead more
Source§fn combinations_after(
&self,
k: usize,
cards: &Cards,
) -> Combinations<IntoIter<Card>>
fn combinations_after( &self, k: usize, cards: &Cards, ) -> Combinations<IntoIter<Card>>
fn combinations_remaining(&self, k: usize) -> Combinations<IntoIter<Card>>
fn par_combinations_remaining( &self, k: usize, ) -> IterBridge<Combinations<IntoIter<Card>>>
Source§fn contains(&self, card: &Card) -> bool
fn contains(&self, card: &Card) -> bool
self.cards().index_set().contains(card), but it broke a lot of
negative tests, since it just stripped out Card::BLANK.fn enumerate_after( &self, k: usize, cards: &Cards, ) -> Enumerate<Combinations<IntoIter<Card>>>
fn enumerate_remaining( &self, k: usize, ) -> Enumerate<Combinations<IntoIter<Card>>>
fn get_rank_bits(&self) -> u16
fn how_many(&self, cards: &Cards) -> usize
fn common(&self, cards: &Cards) -> Cards
Source§fn is_dealt(&self) -> bool
fn is_dealt(&self) -> bool
Pile doesn’t contain
a blank card, and all of the cards are unique, that it has been dealt.fn remaining(&self) -> Cards
fn remaining_after(&self, cards: &Cards) -> Cards
fn ranks_index(&self) -> String
fn suits(&self) -> HashSet<Suit>
fn to_eight_or_better_bits(&self) -> u8
fn evals(&self) -> Evals
Source§impl SuitShift for Card
impl SuitShift for Card
fn shift_suit_down(&self) -> Self
fn shift_suit_up(&self) -> Self
impl Copy for Card
impl Eq for Card
impl StructuralPartialEq for Card
Auto Trait Implementations§
impl Freeze for Card
impl RefUnwindSafe for Card
impl Send for Card
impl Sync for Card
impl Unpin for Card
impl UnsafeUnpin for Card
impl UnwindSafe for Card
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Separable for Twhere
T: Display,
impl<T> Separable for Twhere
T: Display,
Source§fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
SeparatorPolicy. Read moreSource§fn separate_with_commas(&self) -> String
fn separate_with_commas(&self) -> String
Source§fn separate_with_spaces(&self) -> String
fn separate_with_spaces(&self) -> String
Source§fn separate_with_dots(&self) -> String
fn separate_with_dots(&self) -> String
Source§fn separate_with_underscores(&self) -> String
fn separate_with_underscores(&self) -> String
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.