fix: give unneeded fields default values

convenient when composing an json:icf file by hand
This commit is contained in:
beerpsi 2024-01-02 18:19:25 +07:00
parent 0dff839654
commit f34b5ac07f
2 changed files with 14 additions and 3 deletions

View File

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

View File

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