From 0a34deb6309d9a4e3ebc555b41226c720c5497b6 Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Tue, 19 May 2026 08:21:21 -0700 Subject: [PATCH] Game implies Clone + Debug for associated types --- card_game/src/lib.rs | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/card_game/src/lib.rs b/card_game/src/lib.rs index 1a30f3f..cf09d08 100644 --- a/card_game/src/lib.rs +++ b/card_game/src/lib.rs @@ -6,10 +6,10 @@ struct ReadmeDoctests; use core::ops::RangeBounds; // TODO: pub struct ValidInstruction(I); -pub trait Game { - type Stats; - type Config; - type Instruction; +pub trait Game: Clone + core::fmt::Debug { + type Stats: Clone + core::fmt::Debug; + type Config: Clone + core::fmt::Debug; + type Instruction: Clone + core::fmt::Debug; fn possible_instructions(&self) -> impl Iterator + use; fn is_instruction_valid(&self, config: &Self::Config, instruction: Self::Instruction) -> bool; fn process_instruction( @@ -321,28 +321,18 @@ impl SessionStats { } } -#[derive(Clone)] -pub struct Session -where - G::Config: Clone, - G::Instruction: Clone, -{ +#[derive(Clone, Debug)] +pub struct Session { stats: SessionStats, config: G::Config, state: SessionState, } -#[derive(Clone)] -pub struct StateSnapshot -where - G::Instruction: Clone, -{ +#[derive(Clone, Debug)] +pub struct StateSnapshot { state: G, instruction: G::Instruction, } -impl StateSnapshot -where - G::Instruction: Clone, -{ +impl StateSnapshot { pub const fn state(&self) -> &G { &self.state } @@ -350,18 +340,12 @@ where &self.instruction } } -#[derive(Clone)] -pub struct SessionState -where - G::Instruction: Clone, -{ +#[derive(Clone, Debug)] +pub struct SessionState { state: G, history: Vec>, } -impl SessionState -where - G::Instruction: Clone, -{ +impl SessionState { fn new(state: G) -> Self { Self { state, @@ -445,9 +429,7 @@ where } impl Game for SessionState where - G: Clone, G::Stats: Default, - G::Instruction: Clone, { type Stats = SessionStats; type Config = G::Config;