From f34b5ac07f062f1e5f041033dee65bd0395f4390 Mon Sep 17 00:00:00 2001 From: beerpsi Date: Tue, 2 Jan 2024 18:19:25 +0700 Subject: [PATCH] fix: give unneeded fields default values convenient when composing an json:icf file by hand --- README.md | 3 --- src/icf/models.rs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d1d1abc..abf2382 100644 --- a/README.md +++ b/README.md @@ -39,15 +39,12 @@ interface IcfInnerData { interface IcfOptionData { type: "Option", - app_id: string, // Does not go into the ICF, so can be anything, but must be specified option_id: string, // Must be 4 characters - required_system_version: Version, // Can be zeroed out, e.g. { major: 0, minor: 0, build: 0 } datetime: string, // ISO8601 string yyyy-MM-dd'T'HH:mm:ss } interface IcfPatchData { type: "Patch", - id: string, // Does not go into the ICF, so can be anything, but must be specified sequence_number: number, // Incremented for every patch, starting from 1 diff --git a/src/icf/models.rs b/src/icf/models.rs index 1798500..ad1ac7a 100644 --- a/src/icf/models.rs +++ b/src/icf/models.rs @@ -26,14 +26,20 @@ pub struct IcfInnerData { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct IcfOptionData { + #[serde(default = "empty_string")] pub app_id: String, + pub option_id: String, + + #[serde(default = "empty_version")] pub required_system_version: Version, + pub datetime: NaiveDateTime, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct IcfPatchData { + #[serde(default = "empty_string")] pub id: String, pub sequence_number: u8, @@ -90,3 +96,11 @@ impl IcfData { } } } + +fn empty_string() -> String { + String::new() +} + +fn empty_version() -> Version { + Version { major: 0, minor: 0, build: 0 } +} \ No newline at end of file