Game implies Clone + Debug for associated types
This commit is contained in:
+12
-30
@@ -6,10 +6,10 @@ struct ReadmeDoctests;
|
|||||||
use core::ops::RangeBounds;
|
use core::ops::RangeBounds;
|
||||||
|
|
||||||
// TODO: pub struct ValidInstruction<I>(I);
|
// TODO: pub struct ValidInstruction<I>(I);
|
||||||
pub trait Game {
|
pub trait Game: Clone + core::fmt::Debug {
|
||||||
type Stats;
|
type Stats: Clone + core::fmt::Debug;
|
||||||
type Config;
|
type Config: Clone + core::fmt::Debug;
|
||||||
type Instruction;
|
type Instruction: Clone + core::fmt::Debug;
|
||||||
fn possible_instructions(&self) -> impl Iterator<Item = Self::Instruction> + use<Self>;
|
fn possible_instructions(&self) -> impl Iterator<Item = Self::Instruction> + use<Self>;
|
||||||
fn is_instruction_valid(&self, config: &Self::Config, instruction: Self::Instruction) -> bool;
|
fn is_instruction_valid(&self, config: &Self::Config, instruction: Self::Instruction) -> bool;
|
||||||
fn process_instruction(
|
fn process_instruction(
|
||||||
@@ -321,28 +321,18 @@ impl<S> SessionStats<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Session<G: Game>
|
pub struct Session<G: Game> {
|
||||||
where
|
|
||||||
G::Config: Clone,
|
|
||||||
G::Instruction: Clone,
|
|
||||||
{
|
|
||||||
stats: SessionStats<G::Stats>,
|
stats: SessionStats<G::Stats>,
|
||||||
config: G::Config,
|
config: G::Config,
|
||||||
state: SessionState<G>,
|
state: SessionState<G>,
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct StateSnapshot<G: Game>
|
pub struct StateSnapshot<G: Game> {
|
||||||
where
|
|
||||||
G::Instruction: Clone,
|
|
||||||
{
|
|
||||||
state: G,
|
state: G,
|
||||||
instruction: G::Instruction,
|
instruction: G::Instruction,
|
||||||
}
|
}
|
||||||
impl<G: Game> StateSnapshot<G>
|
impl<G: Game> StateSnapshot<G> {
|
||||||
where
|
|
||||||
G::Instruction: Clone,
|
|
||||||
{
|
|
||||||
pub const fn state(&self) -> &G {
|
pub const fn state(&self) -> &G {
|
||||||
&self.state
|
&self.state
|
||||||
}
|
}
|
||||||
@@ -350,18 +340,12 @@ where
|
|||||||
&self.instruction
|
&self.instruction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SessionState<G: Game>
|
pub struct SessionState<G: Game> {
|
||||||
where
|
|
||||||
G::Instruction: Clone,
|
|
||||||
{
|
|
||||||
state: G,
|
state: G,
|
||||||
history: Vec<StateSnapshot<G>>,
|
history: Vec<StateSnapshot<G>>,
|
||||||
}
|
}
|
||||||
impl<G: Game + Clone> SessionState<G>
|
impl<G: Game + Clone> SessionState<G> {
|
||||||
where
|
|
||||||
G::Instruction: Clone,
|
|
||||||
{
|
|
||||||
fn new(state: G) -> Self {
|
fn new(state: G) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state,
|
state,
|
||||||
@@ -445,9 +429,7 @@ where
|
|||||||
}
|
}
|
||||||
impl<G: Game> Game for SessionState<G>
|
impl<G: Game> Game for SessionState<G>
|
||||||
where
|
where
|
||||||
G: Clone,
|
|
||||||
G::Stats: Default,
|
G::Stats: Default,
|
||||||
G::Instruction: Clone,
|
|
||||||
{
|
{
|
||||||
type Stats = SessionStats<G::Stats>;
|
type Stats = SessionStats<G::Stats>;
|
||||||
type Config = G::Config;
|
type Config = G::Config;
|
||||||
|
|||||||
Reference in New Issue
Block a user