Game implies Clone + Debug for associated types

This commit is contained in:
2026-05-19 08:21:21 -07:00
parent bc05bbdc50
commit 0a34deb630
+12 -30
View File
@@ -6,10 +6,10 @@ struct ReadmeDoctests;
use core::ops::RangeBounds;
// TODO: pub struct ValidInstruction<I>(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<Item = Self::Instruction> + use<Self>;
fn is_instruction_valid(&self, config: &Self::Config, instruction: Self::Instruction) -> bool;
fn process_instruction(
@@ -321,28 +321,18 @@ impl<S> SessionStats<S> {
}
}
#[derive(Clone)]
pub struct Session<G: Game>
where
G::Config: Clone,
G::Instruction: Clone,
{
#[derive(Clone, Debug)]
pub struct Session<G: Game> {
stats: SessionStats<G::Stats>,
config: G::Config,
state: SessionState<G>,
}
#[derive(Clone)]
pub struct StateSnapshot<G: Game>
where
G::Instruction: Clone,
{
#[derive(Clone, Debug)]
pub struct StateSnapshot<G: Game> {
state: G,
instruction: G::Instruction,
}
impl<G: Game> StateSnapshot<G>
where
G::Instruction: Clone,
{
impl<G: Game> StateSnapshot<G> {
pub const fn state(&self) -> &G {
&self.state
}
@@ -350,18 +340,12 @@ where
&self.instruction
}
}
#[derive(Clone)]
pub struct SessionState<G: Game>
where
G::Instruction: Clone,
{
#[derive(Clone, Debug)]
pub struct SessionState<G: Game> {
state: G,
history: Vec<StateSnapshot<G>>,
}
impl<G: Game + Clone> SessionState<G>
where
G::Instruction: Clone,
{
impl<G: Game + Clone> SessionState<G> {
fn new(state: G) -> Self {
Self {
state,
@@ -445,9 +429,7 @@ where
}
impl<G: Game> Game for SessionState<G>
where
G: Clone,
G::Stats: Default,
G::Instruction: Clone,
{
type Stats = SessionStats<G::Stats>;
type Config = G::Config;