ksudoku.rs 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Read a Ksudoku's XML save file.
  2. use serde_derive::{Deserialize, Serialize};
  3. use serde_xml_rs::from_reader; // , from_str, to_string};
  4. use std::error::Error;
  5. use std::fs::File;
  6. #[derive(Debug, Serialize, Deserialize, PartialEq)]
  7. struct Graph {
  8. order: i32,
  9. #[serde(rename = "type")]
  10. game_type: String,
  11. #[serde(rename = "specific-type")]
  12. specific_type: String,
  13. }
  14. #[derive(Debug, Serialize, Deserialize, PartialEq)]
  15. struct Puzzle {
  16. graph: Graph,
  17. values: String,
  18. solution: String,
  19. }
  20. #[derive(Debug, Serialize, Deserialize, PartialEq)]
  21. struct Game {
  22. #[serde(rename = "had-help")]
  23. help: i16,
  24. #[serde(rename = "msecs-elapsed")]
  25. elapsed: u32,
  26. puzzle: Puzzle,
  27. }
  28. #[derive(Debug, Serialize, Deserialize, PartialEq)]
  29. struct Ksudoku {
  30. game: Game,
  31. }
  32. pub fn load_ksudoku(filename: std::path::PathBuf) -> Result<String, Box<dyn Error>> {
  33. let fh = File::open(filename)?;
  34. let puzzle: Ksudoku = from_reader(fh)?;
  35. Ok(puzzle.game.puzzle.values.clone())
  36. }