Skip to main content

repl_core/
session.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use uuid::Uuid;
5
6#[derive(Serialize, Deserialize)]
7pub struct Session {
8    pub variables: HashMap<String, String>,
9    pub rng_seed: u64,
10    // We will add clock state later
11}
12
13/// Session snapshot for state management
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct SessionSnapshot {
16    pub id: Uuid,
17    pub timestamp: DateTime<Utc>,
18    pub data: serde_json::Value,
19}
20
21impl Default for Session {
22    fn default() -> Self {
23        Self::new()
24    }
25}
26
27impl Session {
28    pub fn new() -> Self {
29        Self {
30            variables: HashMap::new(),
31            rng_seed: 0,
32        }
33    }
34
35    pub fn snapshot(&self) -> Result<String, serde_json::Error> {
36        serde_json::to_string(self)
37    }
38
39    pub fn restore(snapshot: &str) -> Result<Self, serde_json::Error> {
40        serde_json::from_str(snapshot)
41    }
42}