use struct in serialize impl
This commit is contained in:
+18
-6
@@ -716,8 +716,18 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use serde::ser::SerializeStruct;
|
#[derive(serde_derive::Serialize)]
|
||||||
let mut map = serializer.serialize_struct("Session", 3)?;
|
#[serde(bound(serialize = "
|
||||||
|
G: serde::Serialize,
|
||||||
|
SessionConfig<G::Config>: serde::Serialize,
|
||||||
|
G::Instruction: serde::Serialize,
|
||||||
|
"))]
|
||||||
|
struct SerializedSession<'a, G: Game> {
|
||||||
|
config: &'a SessionConfig<G::Config>,
|
||||||
|
state: &'a G,
|
||||||
|
history: History<'a, G>,
|
||||||
|
}
|
||||||
|
|
||||||
// serialize the initial state of the game.
|
// serialize the initial state of the game.
|
||||||
// if there is history, it is the first snapshot's state,
|
// if there is history, it is the first snapshot's state,
|
||||||
// otherwise it is the current game state since there are no moves.
|
// otherwise it is the current game state since there are no moves.
|
||||||
@@ -726,9 +736,11 @@ where
|
|||||||
} else {
|
} else {
|
||||||
&self.state.state
|
&self.state.state
|
||||||
};
|
};
|
||||||
map.serialize_field("config", &self.config)?;
|
let session = SerializedSession {
|
||||||
map.serialize_field("state", state)?;
|
config: &self.config,
|
||||||
map.serialize_field("history", &History(&self.state.history))?;
|
state,
|
||||||
map.end()
|
history: History(&self.state.history),
|
||||||
|
};
|
||||||
|
session.serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user