From e5c26e35fdd498bea5ac037dce99e36fd34d2e49 Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Mon, 18 May 2026 11:26:39 -0700 Subject: [PATCH] add suit from u8 --- card_game/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/card_game/src/lib.rs b/card_game/src/lib.rs index a2c14c7..a4f809c 100644 --- a/card_game/src/lib.rs +++ b/card_game/src/lib.rs @@ -46,6 +46,16 @@ pub enum Suit { } impl Suit { pub const SUITS: [Self; 4] = [Self::Spades, Self::Hearts, Self::Clubs, Self::Diamonds]; + pub const fn new(suit: u8) -> Option { + use Suit::*; + Some(match suit { + 0b00 => Spades, + 0b01 => Hearts, + 0b10 => Clubs, + 0b11 => Diamonds, + _ => return None, + }) + } /// Is the suit red. pub const fn is_red(self) -> bool { self as u8 & 0b01 != 0