serde for Session
This commit is contained in:
@@ -422,6 +422,10 @@ pub enum SessionInstruction<I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde_derive::Deserialize, serde_derive::Serialize)
|
||||||
|
)]
|
||||||
pub struct SessionStats<S> {
|
pub struct SessionStats<S> {
|
||||||
inner: S,
|
inner: S,
|
||||||
undos: u32,
|
undos: u32,
|
||||||
@@ -438,6 +442,10 @@ impl<S> SessionStats<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde_derive::Deserialize, serde_derive::Serialize)
|
||||||
|
)]
|
||||||
pub struct SessionConfig<C> {
|
pub struct SessionConfig<C> {
|
||||||
pub inner: C,
|
pub inner: C,
|
||||||
pub undo_penalty: i32,
|
pub undo_penalty: i32,
|
||||||
@@ -461,12 +469,26 @@ impl<C: Default> Default for SessionConfig<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde_derive::Deserialize, serde_derive::Serialize),
|
||||||
|
serde(bound = "
|
||||||
|
G: serde::Serialize + for <'a> serde::Deserialize<'a>,
|
||||||
|
G::Stats: serde::Serialize + for <'a> serde::Deserialize<'a>,
|
||||||
|
G::Config: serde::Serialize + for <'a> serde::Deserialize<'a>,
|
||||||
|
Vec<StateSnapshot<G>>: serde::Serialize + for <'a> serde::Deserialize<'a>,
|
||||||
|
")
|
||||||
|
)]
|
||||||
pub struct Session<G: Game> {
|
pub struct Session<G: Game> {
|
||||||
stats: SessionStats<G::Stats>,
|
stats: SessionStats<G::Stats>,
|
||||||
config: SessionConfig<G::Config>,
|
config: SessionConfig<G::Config>,
|
||||||
state: SessionState<G>,
|
state: SessionState<G>,
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde_derive::Deserialize, serde_derive::Serialize)
|
||||||
|
)]
|
||||||
pub struct StateSnapshot<G: Game> {
|
pub struct StateSnapshot<G: Game> {
|
||||||
state: G,
|
state: G,
|
||||||
instruction: G::Instruction,
|
instruction: G::Instruction,
|
||||||
@@ -480,6 +502,14 @@ impl<G: Game> StateSnapshot<G> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde_derive::Deserialize, serde_derive::Serialize),
|
||||||
|
serde(bound = "
|
||||||
|
G: serde::Serialize + for <'a> serde::Deserialize<'a>,
|
||||||
|
Vec<StateSnapshot<G>>: serde::Serialize + for <'a> serde::Deserialize<'a>,
|
||||||
|
")
|
||||||
|
)]
|
||||||
pub struct SessionState<G: Game> {
|
pub struct SessionState<G: Game> {
|
||||||
state: G,
|
state: G,
|
||||||
history: Vec<StateSnapshot<G>>,
|
history: Vec<StateSnapshot<G>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user