123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // Read a Ksudoku's XML save file.
- use serde_derive::{Deserialize, Serialize};
- use serde_xml_rs::from_reader; // , from_str, to_string};
- use std::error::Error;
- use std::fs::File;
- #[derive(Debug, Serialize, Deserialize, PartialEq)]
- struct Graph {
- order: i32,
- #[serde(rename = "type")]
- game_type: String,
- #[serde(rename = "specific-type")]
- specific_type: String,
- }
- #[derive(Debug, Serialize, Deserialize, PartialEq)]
- struct Puzzle {
- graph: Graph,
- values: String,
- solution: String,
- }
- #[derive(Debug, Serialize, Deserialize, PartialEq)]
- struct Game {
- #[serde(rename = "had-help")]
- help: i16,
- #[serde(rename = "msecs-elapsed")]
- elapsed: u32,
- puzzle: Puzzle,
- }
- #[derive(Debug, Serialize, Deserialize, PartialEq)]
- struct Ksudoku {
- game: Game,
- }
- pub fn load_ksudoku(filename: std::path::PathBuf) -> Result<String, Box<dyn Error>> {
- let fh = File::open(filename)?;
- let puzzle: Ksudoku = from_reader(fh)?;
- Ok(puzzle.game.puzzle.values.clone())
- }
|