From 9ee1a0228d02a0a35c4aa47356cb49867259dc3a Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 7 Apr 2026 12:29:49 +0100 Subject: [PATCH] card:hash: implement hashing for ranks, suits, playing cards --- src/card/hash.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/card/hash.rs b/src/card/hash.rs index 84f7840..7457f12 100644 --- a/src/card/hash.rs +++ b/src/card/hash.rs @@ -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(&self, state: &mut H) { + (*self as i64).hash(state); + } +} + +impl Hash for Suit { + fn hash(&self, state: &mut H) { + (*self as i64).hash(state); + } +} + +impl Hash for PlayingCard { + fn hash(&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(&self, state: &mut H) { // NOTE: We're using the i64 conversion of card for the hash since that