From 2678d2d3dd013903c92bc65f34b27c734a6e8762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asger=20Juul=20Brunsh=C3=B8j?= Date: Wed, 22 Jan 2025 23:18:27 +0100 Subject: [PATCH] feat: add state version to State --- Cargo.lock | 12 ++++++++++++ crates/ascend/Cargo.toml | 1 + crates/ascend/src/server.rs | 9 ++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 04376e6..2e49dde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,6 +120,7 @@ dependencies = [ "serde", "serde_json", "server_fn", + "smart-default", "tokio", "tower 0.4.13", "tower-http 0.5.2", @@ -2333,6 +2334,17 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "smart-default" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "socket2" version = "0.5.8" diff --git a/crates/ascend/Cargo.toml b/crates/ascend/Cargo.toml index faa9c25..4053cd2 100644 --- a/crates/ascend/Cargo.toml +++ b/crates/ascend/Cargo.toml @@ -34,6 +34,7 @@ tracing-subscriber-wasm = "0.1.0" ron = { version = "0.8" } rand = { version = "0.8", optional = true } web-sys = { version = "0.3.76", features = ["File", "FileList"] } +smart-default = "0.7.1" [dev-dependencies.serde_json] version = "1" diff --git a/crates/ascend/src/server.rs b/crates/ascend/src/server.rs index ba6c49e..31254d5 100644 --- a/crates/ascend/src/server.rs +++ b/crates/ascend/src/server.rs @@ -43,11 +43,14 @@ pub mod cli { pub mod state { //! Server state + const STATE_VERSION: u64 = 1; + use super::persistence::Persistent; use crate::models; use crate::models::Wall; use serde::Deserialize; use serde::Serialize; + use smart_default::SmartDefault; use std::collections::BTreeSet; #[derive(Clone, Debug)] @@ -55,8 +58,12 @@ pub mod state { pub persistent: Persistent, } - #[derive(Serialize, Deserialize, Clone, Debug, Default)] + #[derive(Serialize, Deserialize, Clone, Debug, SmartDefault)] pub struct PersistentState { + /// State schema version + #[default(STATE_VERSION)] + pub version: u64, + pub wall: Wall, pub problems: Problems, }