use super::{state::SplitStatus, Comparison, DiffType, Run, TimeType};
use crate::error::Result;
use ron::{de::from_reader, ser::to_string};
use serde::{Deserialize, Serialize};
use std::fs::File;
use std::path::Path;
#[derive(Serialize, Deserialize)]
pub struct StateDump {
pub run: Run,
pub status: SplitStatus,
pub comparison: Comparison,
pub run_times: Vec<TimeType>,
pub run_diffs: Vec<DiffType>,
pub run_golds: Vec<bool>,
pub before_pause: u128,
pub before_pause_split: u128,
pub time: u128,
pub current_split: usize,
pub needs_save: bool,
}
impl StateDump {
pub fn open<P: AsRef<Path>>(filename: P) -> Result<Self> {
Ok(from_reader(File::open(filename)?)?)
}
pub fn write<P: AsRef<Path>>(&self, filename: P) -> Result<()> {
Ok(std::fs::write(filename, to_string(self)?)?)
}
}