wip: parse moonboard

This commit is contained in:
2025-01-12 16:58:30 +01:00
parent ea43e71c30
commit 8af5acba4b
24 changed files with 15126805 additions and 131 deletions

View File

@@ -0,0 +1,57 @@
use camino::Utf8PathBuf;
pub mod mini_moonboard {
use crate::Error;
use camino::Utf8PathBuf;
use serde::Deserialize;
pub const MINI_MOONBOARD_PROBLEMS: &str = "moonboard-problems/problems Mini MoonBoard 2020 40.json";
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MiniMoonboardProblems {
total: u64,
data: Vec<Data>,
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Data {}
pub async fn parse() -> Result<MiniMoonboardProblems, Error> {
let file_path = Utf8PathBuf::from(MINI_MOONBOARD_PROBLEMS);
let content = tokio::fs::read_to_string(&file_path).await.map_err(|source| Error::Read {
file_path: file_path.to_owned(),
source,
})?;
let t: MiniMoonboardProblems = serde_json::from_str(&content).map_err(|source| Error::Deserialize {
file_path: file_path.to_owned(),
source,
})?;
Ok(t)
}
#[cfg(test)]
#[tokio::test]
async fn test_parse() {
parse().await.unwrap();
}
}
#[derive(Debug, derive_more::Error, derive_more::Display)]
#[display("Persistent state error: {_variant}")]
pub enum Error {
#[display("Failed to read file: {file_path}")]
Read { file_path: Utf8PathBuf, source: std::io::Error },
#[display("Failed to deserialize state from file: {file_path}")]
Deserialize { file_path: Utf8PathBuf, source: serde_json::Error },
#[display("Failed to serialize state")]
Serialize { source: serde_json::Error },
#[display("Failed to write file: {file_path}")]
Write { file_path: Utf8PathBuf, source: std::io::Error },
}