feat: add state version to State

This commit is contained in:
Asger Juul Brunshøj 2025-01-22 23:18:27 +01:00
parent 993ba8d408
commit 2678d2d3dd
3 changed files with 21 additions and 1 deletions

12
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -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<PersistentState>,
}
#[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,
}