This commit is contained in:
2026-05-30 10:44:33 -07:00
parent fadefe93c2
commit b6e9d9fbdd
+9 -4
View File
@@ -663,19 +663,24 @@ where
} }
#[cfg(feature = "serde")] #[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 where
G: serde::Deserialize<'de>, G: serde::Deserialize<'de>,
G::Instruction: 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 where
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
struct SessionStateVisitor<G> { struct SessionStateVisitor<G> {
state: 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>; type Value = SessionState<G>;
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "State History") write!(f, "State History")
@@ -689,7 +694,7 @@ where
Some(capacity) => Vec::with_capacity(capacity), Some(capacity) => Vec::with_capacity(capacity),
None => Vec::new(), None => Vec::new(),
}; };
while let Some(instruction) = seq.next_element()? { while let Some(instruction) = seq.next_element::<G::Instruction>()? {
history.push(StateSnapshot { history.push(StateSnapshot {
state: state.clone(), state: state.clone(),
instruction: instruction.clone(), instruction: instruction.clone(),