use crate::objects::{MajorMinor, Object, ObjectKind};
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Cache {
pub kind: ObjectKind,
pub version: MajorMinor,
pub entries: Vec<Entry>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Entry {
pub name: String,
pub value: String,
#[serde(rename = "type")]
pub type_name: String,
pub properties: Vec<Property>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Property {
pub name: String,
pub value: String,
}
impl Object for Cache {
fn kind() -> ObjectKind {
ObjectKind::Cache
}
fn major() -> u32 {
2
}
}
#[cfg(test)]
mod tests {
use crate::objects::cache_v2::*;
use serde_json::json;
#[test]
fn test_configure_log() {
let json = json!({
"kind": "cache",
"version": { "major": 2, "minor": 0 },
"entries": [
{
"name": "BUILD_SHARED_LIBS",
"value": "ON",
"type": "BOOL",
"properties": [
{
"name": "HELPSTRING",
"value": "Build shared libraries"
}
]
},
{
"name": "CMAKE_GENERATOR",
"value": "Unix Makefiles",
"type": "INTERNAL",
"properties": [
{
"name": "HELPSTRING",
"value": "Name of generator."
}
]
}
]
});
let cache = serde_json::from_value::<Cache>(json).unwrap();
assert_eq!(
cache,
Cache {
kind: ObjectKind::Cache,
version: MajorMinor { major: 2, minor: 0 },
entries: vec![
Entry {
name: "BUILD_SHARED_LIBS".into(),
value: "ON".into(),
type_name: "BOOL".into(),
properties: vec![Property {
name: "HELPSTRING".into(),
value: "Build shared libraries".into(),
}]
},
Entry {
name: "CMAKE_GENERATOR".into(),
value: "Unix Makefiles".into(),
type_name: "INTERNAL".into(),
properties: vec![Property {
name: "HELPSTRING".into(),
value: "Name of generator.".into(),
}]
}
]
}
);
}
}