card#️⃣ implement hashing for ranks, suits, playing cards

This commit is contained in:
2026-04-07 12:29:49 +01:00
committed by oreodave
parent ec31844ee7
commit 9ee1a0228d

View File

@@ -1,6 +1,26 @@
use crate::card::Card;
use crate::card::{Card, PlayingCard, Rank, Suit};
use std::hash::{Hash, Hasher};
impl Hash for Rank {
fn hash<H: Hasher>(&self, state: &mut H) {
(*self as i64).hash(state);
}
}
impl Hash for Suit {
fn hash<H: Hasher>(&self, state: &mut H) {
(*self as i64).hash(state);
}
}
impl Hash for PlayingCard {
fn hash<H: Hasher>(&self, state: &mut H) {
// NOTE: We're using the i64 conversion of card for the hash since that
// should generate unique numbers per card.
i64::from(*self).hash(state);
}
}
impl Hash for Card {
fn hash<H: Hasher>(&self, state: &mut H) {
// NOTE: We're using the i64 conversion of card for the hash since that