Skip to main content

save_to_string

Function save_to_string 

Source
pub fn save_to_string(state: &GameState) -> Result<String>
Expand description

Serialize the live state to its on-disk JSON form. The version field is whatever the caller has on stateGameState::default() and the migration chain both stamp CURRENT_VERSION, so the only way to write a wrong version is to mutate state.version by hand, which nothing does.

Sanitizes non-finite f64 fields (NaN / INFINITY) to 0.0 before serializing, since serde_json refuses to serialize non-finite f64 and historically callers let _ =-swallowed the resulting Err — the player’s progress would silently stop being written. Reaching a non-finite value normally is impossible, but a corrupted save loaded once can poison cuques / lifetime_cuques and we’d rather lose the corruption than lose subsequent saves.