wag
This commit is contained in:
+10
-5
@@ -663,19 +663,24 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de, G: Game> serde::Deserialize<'de> for SessionState<G>
|
||||
impl<'de, G: Game> serde::de::DeserializeSeed<'de> for Session<G>
|
||||
where
|
||||
G: serde::Deserialize<'de>,
|
||||
G::Instruction: serde::Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
type Value = SessionState<G>;
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
struct SessionStateVisitor<G> {
|
||||
state: G,
|
||||
}
|
||||
impl<'de, G: Game> serde::de::Visitor<'de> for SessionStateVisitor<G> {
|
||||
impl<'de, G: Game> serde::de::Visitor<'de> for SessionStateVisitor<G>
|
||||
where
|
||||
G: serde::Deserialize<'de>,
|
||||
G::Instruction: serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = SessionState<G>;
|
||||
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "State History")
|
||||
@@ -689,7 +694,7 @@ where
|
||||
Some(capacity) => Vec::with_capacity(capacity),
|
||||
None => Vec::new(),
|
||||
};
|
||||
while let Some(instruction) = seq.next_element()? {
|
||||
while let Some(instruction) = seq.next_element::<G::Instruction>()? {
|
||||
history.push(StateSnapshot {
|
||||
state: state.clone(),
|
||||
instruction: instruction.clone(),
|
||||
@@ -715,7 +720,7 @@ where
|
||||
{
|
||||
if let Some(state) = self.history.first() {
|
||||
state.serialize(serializer)?;
|
||||
}else{
|
||||
} else {
|
||||
self.state.serialize(serializer)?;
|
||||
}
|
||||
use serde::ser::SerializeSeq;
|
||||
|
||||
Reference in New Issue
Block a user